Get two fields from a record in VB.Net
I have been working with VB demos / tutorials for a while now and am now working on a real project.
I have managed a database connection but am unable to figure out how to get the value of a field from my table based on the employee number.
Here is my code so far:
Code:
Dim strFname As String
Dim strLname As String
Dim cnn As SqlConnection = _
New SqlConnection("workstation id=XXXXX;packet" & _
" size=4096;integrated security=SSPI;data source=XXXXX;" & _
"persist security info=False;initial catalog=DBName")
Dim cmdSelect As New SqlCommand
cnn.Open()
Try
cmdSelect = cnn.CreateCommand
cmdSelect.CommandText = "SELECT Name From PREH where Employee=" & txtEmp.Text
Catch ex As Exception
MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OKOnly, "Error")
End Try
My form has two text boxes one called txtEmpNum and the other txtEmpName. I am trying to write code that will return the name of the employee to the name text box on the LostFocus event which is where that code above is from. Any help would be appreciated.