0
If ssearch.Text <> "" Then
        cmdOLEDB.CommandText = "SELECT StudentID FROM Students WHERE StudentID = " & (ssearch.Text) & " ; "
        cmdOLEDB.Connection = cnnOLEDB

I have tried many solution but none of them helped. Either they pop out a no value etc etc and this error. I'm trying to search Student ID from my access and display it out. Is there an error in the above part. ssearch.text is the textbox in which I type the number I want to search.

sujith karivelil
  • 28,671
  • 6
  • 55
  • 88
user63566
  • 53
  • 7

1 Answers1

0

The Datatype for StudentID in the data base is may not be an integer. but you are passing this field in where condition as an integer. in queries,

String or character is represented within a pair of single quotes(' '). so your query will be like the following:

   cmdOLEDB.CommandText = "SELECT StudentID FROM Students WHERE StudentID = '" & (ssearch.Text) & "';"

but the best way is to use parameterized queries, instead for this to avoid sql injection.

Community
  • 1
  • 1
sujith karivelil
  • 28,671
  • 6
  • 55
  • 88