Solved

Insert data into a table after selecting a  record in a data grid view

Posted on 2009-03-31
6
491 Views
Last Modified: 2013-11-27
Hi all!

I am using VB 2008 Express.
I have two tables: tblInventory and tblTransactions. tblInventory has fields: ID, ItemNo, ItemDescrtiption, QuantityInStock, and Cost while tblTransaction has ID, ItemNo, ItemDescription, TransactionType, Date, and Quantity.
I created a form (frmInventory) with a Filter feature to only display the Items in the Datagrid View which match the criteria in a filter box.
What I wish to happen, after the filtering, is that: when an item/record is  clicked from the datagrid view in frmInventory, my other form, frmTransaction will show and the selected data will automatically populate on the fields particularly the ItemNo and ItemDescription.

Any suggestion and solution you will give is highly appreciated.

Thank you.

Ed

0
Comment
Question by:MINDSUPERB
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 11

Expert Comment

by:srikanthreddyn143
ID: 24029386
How are these two tables related?

Initialize frmTransaction  with the ID from frmInventory. When a row is selected, pass the ID to frm transaction and when form loads get the data from table to populate in the fields.
0
 
LVL 19

Author Comment

by:MINDSUPERB
ID: 24036104
How are these tables related?
They are related by ItemNo.

There is a missing field in tblTransaction that I forgot to include. That is InventoryID.

May I ask how to initialize the frmTransaction and how to pass the ID into another form? Sorry, I am still on the process of learning VB.

thanks.
0
 
LVL 11

Expert Comment

by:srikanthreddyn143
ID: 24038814
In the frmInventory, Once you insert the Inventory record,You will be having ItemNo.

--This part is in frminventory
In the Datagridview click event

Dim objTrans As New frmTransaction
objTrans.Initialize(IItemNo)
objTrans.Show()

-- In frmTransaction
Dim TransItem As Datatype
Public Sub Initialize(ByVal ItemNo As Datatype)
TransItem = ItemNo
EndSub

Private sub frm_Load()
Get the data as dataset from datatable with the itemNo and populate all fields
End Sub
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Expert Comment

by:srikanthreddyn143
ID: 24038960
Here are the events you can use and in the following fashion. Form2 indicates frmtransaction

Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
        Dim f2 As New Form2
        f2.Init(DataGridView1.Rows(e.RowIndex).Cells("txt").Value.ToString)
        f2.Show()
    End Sub
 
    Private Sub DataGridView1_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick
        Dim f2 As New Form2
        f2.Init(DataGridView1.Rows(e.RowIndex).Cells("txt").Value.ToString)
        f2.Show()
    End Sub

Open in new window

0
 
LVL 11

Accepted Solution

by:
srikanthreddyn143 earned 500 total points
ID: 24038970
And in the frm transaction,

Public Class Form2
    Dim il As String
    Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 
    End Sub
 
    Public Sub Init(ByVal s As String)
        il = s
    End Sub
End Class

Open in new window

0
 
LVL 19

Author Closing Comment

by:MINDSUPERB
ID: 31564781
I am sorry for my delayed response.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question