Queriestableadapter

Hi

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…?

Thanks
Paul


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):


Imports System
Imports System.Data.SqlClient

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
Catalog=yourDB;Integrated Security=True”

ds = New Dataset
da = New SqlDataAdapter
da.SelectCommand = New SqlCommand
da.SelectCommand.Connection = conn
da.SelectCommand = “Select * From yourTbl”
da.Fill(ds, “tblSteve”)

datagridview1.DataSource = ds.Tables(“tblSteve”)
End Sub

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.

He forgot a key bit:


da.SelectCommand.CommandText = "Select * From tblteam"

Hi WWB 99

Works a treat…

Many thanks
Paul