I found the useful code below on another Website. However, I can't get it to work in VS 2008 VB.net. When all is entered on the form, I believe correctly, it returns an error on the line:
da.SelectCommand = "Select * From tblteam"
Error is 'value of type 'string' cannot be converted to 'system.data.sqlclient.sqlcommand'
Can anybody suggest what the problem may be..?
Using the wizards will restrict your objects considerably. You are
better off doing this in code as follows (I am using Windows
Authentication in this sample if you are using Sql Server):
Dim conn As SqlConnection, da As SqlDataAdapter
Dim ds As Dataset
Private Sub Form1_Load(...) Handles MyBase.Load
conn1 = New SqlConnection
conn1.ConnectionString = "Data Source=yourSvr;Initial
ds = New Dataset
da = New SqlDataAdapter
da.SelectCommand = New SqlCommand
da.SelectCommand.Connection = conn
da.SelectCommand = "Select * From yourTbl"
datagridview1.DataSource = ds.Tables("tblSteve")
Just create a new form and drop a datagridview control on it. Then copy
and paste the code above into your new form. Replace yourTbl with the
name of an actual table on your server DB. Now load the project and you
will see the data in your form's datagridview control.