Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
VB
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles SUBMITID.Click
        Dim conn As New SqlConnection(" Data Source=NALABI-HP\SQLEXPRESS;Initial Catalog=LeaveManagement;Integrated Security=True ")
        Dim comm As New SqlCommand("Select [Man_ID] from Manager where[Man_Id] = 'Val(manid.Text)'", conn)
        Try
            comm.Connection.Open()
            Dim reader As SqlDataReader = comm.ExecuteReader()

            If reader.HasRows Then
                reader.Read()
            Else
                MessageBox.Show("Manager ID not found")
            End If
        Catch ex As Exception
            MessageBox.Show("Catching Exception")

        Finally
            comm.Connection.Close()
            End Try



    End Sub
Posted

Try this code in sqlcommand

VB
Dim comm As New SqlCommand("Select [Man_ID] from Manager where[Man_Id] = 'Val(" & manid.Text & ")'"
 
Share this answer
 
Comments
NalaBI 22-Oct-12 7:24am    
Thank you xErvender.
I am still getting an excepton error message"Manager ID not found"
xErvender 22-Oct-12 12:22pm    
check ur table if there is a column [Man_ID].
xErvender 22-Oct-12 12:25pm    
check the spaces between where and [Man_ID].. "where [Man_Id]"
What data type is used to store Man_ID value?
If it's string, then try this:
Dim comm As New SqlCommand("Select [Man_ID] from Manager where[Man_Id] = '" & manid.Text & "'", conn)

If it's integer, try this:
VB
Dim comm As New SqlCommand("Select [Man_ID] from Manager where[Man_Id] = " & manid.Text, conn)
 
Share this answer
 
v2
If Data Type OF Man_Id Column is String then use :
SQL
Dim CommandObject As SQLCommand = New SqlCommand("Select [Man_ID] from Manager where[Man_Id] = '" & manid.Text & "'", SQLConnectionObject)

Or IF Data Type is Numeric Or Int Then Use :
SQL
Dim CommandObject As SQLCommand = New SqlCommand("Select [Man_ID] from Manager where[Man_Id] = '" & Val(manid.Text) & "'", SQLConnectionObject)

I hope it will help you. :)
 
Share this answer
 
Thank you xErvender.
I am still getting an that says "Manager ID not found
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900