I have two tables in sql. One is my Department table and the other is my employee table. I have set the Managers of each department using the Employee table GUID that corresponds to there name. I am them trying to load a form where you select the department and then it uses that GUID to populate the managers name and email but when I populate my second dataset its telling me "There is no row at position 0."
If anyone can tell me what I am doing wrong I would appreciate it.
Code:
Private Sub TTDE_Dep_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TTDE_Dep.TextChanged
If TTDE_Dep.Text = "" Then
Else
'Dim sqlConn As New SqlConnection(ConnectionStrings("ITSYS").ConnectionString)
Dim cmd As String = "SELECT TTD_Mgr_TT_Emp_GUID FROM TT_Departments WHERE TTD_Dept= '" + TTDE_Dep.Text + "'"
Dim myCommand As New SqlCommand(cmd, sqlConn)
Dim cmd2 As String = "Select TT_Employee_Name,TT_Employee_Email From TT_Employee WHERE TT_Emp_GUID= '" + GUID + "'"
Dim myCommand2 As New SqlCommand(cmd2, sqlConn)
Dim TTDataAdapter As New SqlDataAdapter
Dim TTDataS As New DataSet
Dim TTDataAdapter2 As New SqlDataAdapter
Dim TTDataS2 As New DataSet
'OleDbConnection i
' open the connection
sqlConn.Open()
TTDataAdapter.SelectCommand = myCommand
TTDataAdapter.Fill(TTDataS)
GUID = TTDataS.Tables(0).Rows(0).Item("TTD_Mgr_TT_Emp_GUID").ToString()
MessageBox.Show(GUID)
TTDataAdapter2.SelectCommand = myCommand2
TTDataAdapter2.Fill(TTDataS2)
TTDE_Manager.Text = TTDataS2.Tables(0).Rows(0).Item("TT_Employee_Name").ToString()
TTDE_Email.Text = TTDataS2.Tables(0).Rows(0).Item("TT_Employee_Email").ToString()
sqlConn.Close()
TTDataAdapter.Dispose()
TTDataS.Dispose()
End If
End Sub