|
-
May 3rd, 2013, 02:28 PM
#1
Thread Starter
Junior Member
[RESOLVED] Get result of a query (single value) into a Visual Basic label
I'm performing a SELECT query to get the student ID. I'm getting the following error:
Conversion from String "SELECT est_ID FROM ESTUDIANTE WH" tp type 'Long' is not valid
Here is the code:
Try
Using Con As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=" & globalvariable.dbpath
& ";Integrated Security=True;User Instance=True")
Con.Open()
Using com As New SqlCommand("SELECT est_id FROM ESTUDIANTE WHERE est_nombre ="
& Val(txtNombre.Text) And "est_apellido =" & Val(txtApellido.Text), Con)
Dim textObj = com.ExecuteScalar
If Not textObj Is Nothing AndAlso Not textObj Is DBNull.Value Then
txtID.Text = CInt(textObj)
End If
End Using
End Using
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
THX...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|