Skip navigation links

MySQL Forums :: Newbie :: Reliable Method to Populate Datagrid in VB.NET 2005 (SOLUTION)


Advanced Search

Reliable Method to Populate Datagrid in VB.NET 2005 (SOLUTION)
Posted by: Jon Money ()
Date: July 05, 2006 01:53PM

I have been searching thru the forums for a reliable way to display table data in a DataGridView in Visual Basic.NET 2005 Express. After putting a few solutions together, I have arrived at the following code. Bear in mind that the following only *displays* the data; there is no code written to add, update or delete (yet.)


Dim mySQLDS As New DataSet
Dim connString As String = (Your database connection string here)
Dim qryMySQL As String = "SELECT * FROM (Your Table Name)"
Dim conn As New MySqlConnection
conn.ConnectionString = connString
Dim cmd As MySqlCommand = New MySqlCommand(qryMySQL)
Dim adapt As New MySqlDataAdapter
adapt.SelectCommand = New MySqlCommand(qryMySQL, conn)
adapt.Fill(mySQLDS)
DataGridView1.DataSource = mySQLDS.Tables(0)
DataGridView1.Update()


Thanks to many of you that have helped others and I hope this example helps more of us "newbies".



Edited 1 time(s). Last edit at 07/05/2006 01:58PM by Jon Money.

Options: ReplyQuote


Subject Written By Posted
Reliable Method to Populate Datagrid in VB.NET 2005 (SOLUTION) Jon Money 07/05/2006 01:53PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.