Basic databinding on forms

Mondeo

Centurion
Joined
Nov 10, 2006
Messages
128
Location
Sunny Lancashire
I have a simple database app, tab 1 has a datagrid on which is filled simply with SELECT * FROM Customers into a dataset/datatable which is then bound to the grid.

Then if I double click a row it moves to tab 2, looks up cell 1 on the selected row of the datagrid (which is the primary key) and then does "SELECT * FROM Customers WHERE ID=id" into a datareader.

On tab 2 I have loads of text boxes and I simply do

txtname.text = rdr.item(0).tostring
txtcompany. text = rdr.item(1).tostring

And so on.

Could someone explain the correct and accepted way of doing this task, i.e. using databinding etc. Should I create a customer class first with properties for my database fields? Then how to I do the binding etc.

Thanks
 
simple query using data reader

Dim conn as new MySqlConnection(.......)
If conn.State = ConnectionState.Closed Then
conn.Open()
End If

Dim cmd As MySqlCommand
Dim dtr As MySqlDataReader
Dim query As String

query = "your query"

cmd = New MySqlCommand(query, conn)

dtr = cmd.ExecuteReader
While dtr.Read
'add items into data table/datagrid
messagebox.show(dtr.item(0).tostring)
End While
dtr.Close()

'hope this help
 
Hi George,

Yes this is exactly what I have at the moment, but I want to learn more about using the more advanced (and probably quicker!) databinding features, like databinding to objects etc.
 
Back
Top