SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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.

  2. #2
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,649
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    He forgot a key bit:

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

  3. #3
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi WWB 99

    Works a treat...

    Many thanks
    Paul


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •