Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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

George C.K. Low

Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...