0
   Dim myconn As New SqlConnection("Server=server,Trusted_Connection=True,Database=database")
    'selects from mt table linking the current pc to a row
    Dim sql As String = "SELECT * from idset " & vbcrlf &
    "Where pcname= '" & pcname & "'"
    Dim ds As New DataSet
    Dim da As New SqlDataAdapter(sql, myconn)

    da.Fill(ds, "Setup")


    txtClientID.DataBindings.Add("text", ds.Tables("idset"), "CLID")

I don't know why its not working for some reason its not filling the data set did I declare something wrong?

stakx - no longer contributing
  • 83,039
  • 20
  • 168
  • 268
c.goss
  • 29
  • 6
  • Your edit made the currently accepted answer appear incorrect, because it referred to an error that was no longer present. Since you didn't comment on why you accepted [that answer](http://stackoverflow.com/a/25748228/240733), it seemed better to roll back your edit than to update the answer. – stakx - no longer contributing Sep 09 '14 at 18:57

1 Answers1

3

The reason why it don't work is because you specify that the incoming table should be mapped to a table named Setup. Your data set doesn't contain a table named Setup, so the incoming table will be named... well, Setup.

Try this instead:

da.Fill(ds, "idset")

Also, I strongly suggest you:

Seriously.


The best way to debug bindings is to use a BindingSource and handle the BindingComplete event.

Private bs As BindingSource
Private ds As DataSet

Private Sub Initialize(pcname As String)

    Me.ds = New DataSet()

    Using connection As New SqlConnection("Server=server,Trusted_Connection=True,Database=database")
        connection.Open()
        Using command As New SqlCommand()
            command.Connection = connection
            command.CommandText = "SELECT * from [idset] Where [pcname] = @pcname;"
            command.Parameters.AddWithValue("@pcname", pcname)
            Using adapter As New SqlDataAdapter(command)
                adapter.Fill(Me.ds, "idset")
            End Using
        End Using
    End Using

    Me.bs = New BindingSource(Me.ds, "idset")

    AddHandler bs.BindingComplete, AddressOf Me.HandleBindingCompleted

    Me.txtClientID.DataBindings.Add("Text", Me.bs, "CLID")

End Sub

Private Sub HandleBindingCompleted(sender As Object, e As BindingCompleteEventArgs)
    If (Not e.Exception Is Nothing) Then
        Debug.WriteLine(e.ErrorText)
    End If
End Sub
Community
  • 1
  • 1
Bjørn-Roger Kringsjå
  • 9,849
  • 6
  • 36
  • 64
  • Sorry about that I had named the table setup. My boss came in early and changed names on me still rooting out errors in other place :(. Will look at that. – c.goss Sep 09 '14 at 15:20
  • Changed around still not getting anything. The sql statement against the server directly through ssms works fine pulling up the row i want just it not seeming to bind. – c.goss Sep 09 '14 at 15:25
  • Thanks alot i have alot more reading to do now to understand what you have done. – c.goss Sep 09 '14 at 16:10