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)
Try
Dim sSQL As String
sSQL = "Select * from tvwLeads where numLeadID=" & numSelected & " order by numLeadID"
MsgBox(numSelected)
Dim dbadp As New SqlDataAdapter(sSQL, sqlComm)
Dim dTable As New DataTable
dbadp.Fill(dTable)
dbadp.Dispose()
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
MsgBox(ex.Message)
End Try
End Sub
that means that your select query returns no row and you are trying to update the first row (index = 0)