Transfer of data from listbox to table

wasim

New member
Joined
May 17, 2009
Messages
2
Programming Experience
Beginner
I am using vb Express 2008 and MsAccess as database.
i have two comboboxes combDescription,combPrice and two textboxes txtQuantity,txtAmount.
data is transferred from these two comboboxes and two textboxes to display in listbox like:
Description, Quantity, Price, Amount
order1 2 3 6
order2 2 4 8
order3 2 4 8
order4 2 5 10
Total 32

Now this data from list box is to be saved in a table which has the same columns as of listbox and ofcourse of same datatype. i want to save this data in that table with one Id so that the said data after be retrieved back into the listbox and after some additions of more orders saved back into that table under the same Id.
Kindly advise me to code for that.
 
Thanks for your response.
I tried datagridview as you suggested. i have following code for that it is working well for read and delete buttons. But for Insert and Update it is giving synex error............at cmd.ExecuteNonQuery() for INSERT INTO.
kindly advise where i am doing wrong.

' Read record

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

cmd = New OleDbCommand("SELECT * FROM Users Where name='Martin'", con)

If con.State = ConnectionState.Closed Then con.Open()

Dim sdr As OleDbDataReader = cmd.ExecuteReader()

While sdr.Read = True

MessageBox.Show(sdr.Item("name") & " " & sdr.Item("phone"))

End While

sdr.Close()

End Sub



' Insert record

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

cmd = New OleDbCommand("Insert Into Users(name, phone) Values('phenry', ‘88866677’)", con)

If con.State = ConnectionState.Closed Then con.Open()

cmd.ExecuteNonQuery()

ShowData() 'Rebinding to DataGridView and view result

End Sub



' Update record

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

cmd = New OleDbCommand("Update Users Set phone=’34’ Where name='Martin'", con)

If con.State = ConnectionState.Closed Then con.Open()

cmd.ExecuteNonQuery()

ShowData() 'Rebinding to DataGridView and view result

End Sub



'Delete record

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

cmd = New OleDbCommand("Delete * From Users Where name='Martin'", con)

If con.State = ConnectionState.Closed Then con.Open()

cmd.ExecuteNonQuery()

ShowData() 'Rebinding to DataGridView and view result

End Sub



' Dispose Database Connection object

Private Sub Form4_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed

con.Close()

con = Nothing

End Sub
 
kindly advise where i am doing wrong
There are too many errors in your code to appraise you of them all. Instead, you should read the DW2 link in my signature, starting with the section Creating a Simple Data Application.

Following that advice I can get an app that shows table data in a grid, and saves it, up and running perfectly in about 2 minutes flat.
 

Latest posts

Back
Top