troubleshooting Question dataset errors connecting to SQL server and displaying fields on form.

Avatar of smm6809
smm6809 asked on
Visual Basic.NETMicrosoft SQL Server 2008
17 Comments1 Solution61 ViewsLast Modified:
New to SQL and VB.Net but have used Access and VBA for years. I have a couple of questions regarding the code below. I get an error saying there is no row at position 0. I don't even know what that means, let alone what to do about it. Also, I have 3 comboboxes on the form I am trying to populate. They fill automatically when the form loads, but I want them to select the item that represents the specific record in the database. For example: I have 10 stores in the dropdown, but the record I am trying to retrieve is associated with the ID 5. It's DisplayMember is the name of the store, but its ValueMember is an ID. I want the combobox to select the the ID associated with the record in SQL and then display the DisplayMember correctly. Can I do this? Here is the code:
Public Sub psFillDataset()
        Dim conn As New SqlConnection(sqlComm)
            Dim sSQL As String
            sSQL = "Select * from tvwLeads where numLeadID=" & numSelected & " order by numLeadID"
            Dim dbadp As New SqlDataAdapter(sSQL, sqlComm)
            Dim dTable As New DataTable
            Me.txtSource.DataSource = dTable
            Me.txtType.Text = ("strType").ToString()
            Me.txtClient.Text = ("numClient").ToString()
            Me.txtLast.Text = dTable.Rows(0)("strLast").ToString()
            Me.txtFirst.Text = dTable.Rows(0)("strFirst").ToString()
            Me.tmTO.Text = dTable.Rows(0)("tmTO").ToString()
            Me.dtTO.Text = dTable.Rows(0)("dtTO").ToString()
            Me.tmCT.Text = dTable.Rows(0)("tmCTC").ToString()
            Me.dtCT.Text = dTable.Rows(0)("dtCTC").ToString()
            Me.chkBad.Text = dTable.Rows(0)("ysnBad").ToString()
            Me.txtManager.Text = dTable.Rows(0)("strManager").ToString()
            Me.cboSales.Text = dTable.Rows(0)("strName").ToString()
            Me.txtNotes.Text = dTable.Rows(0)("strNotes").ToString()
            Me.txtEmail.Text = dTable.Rows(0)("strResponse").ToString()
            Me.txtID.Text = dTable.Rows(0)("numLeadID").ToString()
            Me.txtSource.DisplayMember = "strSource"
            Me.cboVehicle.DisplayMember = "strLeadType"
        Catch ex As Exception
        End Try

    End Sub
Éric Moreau
Senior .Net Consultant
Join our community to see this answer!
Unlock 1 Answer and 17 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 17 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros