I have a table that looks like thisTable When I use this code it works fine
Private Sub CountData()
Dim con As New SqlConnection
Dim cmd As New SqlCommand
Try
con.ConnectionString = "Data Source=LVAPP; Initial Catalog=CFLineTracker;Persist Security Info=True;User ID=CFLineAdmin;Password=aaonunit#1"
con.Open()
cmd.Connection = con
cmd.CommandText = "SELECT COUNT(*) FROM ItemDetails where ItemMasterId = " & IMID & ""
RD = cmd.ExecuteScalar
Label5.Text = RD
Catch ex As Exception
MessageBox.Show("Error while inserting record on table..." & ex.Message, "Insert Records")
Finally
con.Close()
End Try
End Sub
But when I try to run this code I get an exception
Private Sub CountData()
Dim con As New SqlConnection
Dim cmd As New SqlCommand
con.ConnectionString = "Data Source=LVAPP; Initial Catalog=CFLineTracker;Persist Security Info=True;User ID=CFLineAdmin;Password=aaonunit#1"
con.Open()
cmd.Connection = con
cmd.CommandText = "SELECT COUNT(*) FROM ItemDetails where Serial Number = " & SN & ""
RDSN = cmd.ExecuteScalar
Label5.Text = RDSN
End Sub
The SQL Exception is:
Additional information: An expression of non-boolean type specified in a context where a condition is expected, near 'Number'.
I'm using SQL SERVER 2008 R2 VB.net 2013