By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,285 Members | 1,659 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,285 IT Pros & Developers. It's quick & easy.

Select * from tablename where ID = '"& textbox1.text & "'

P: 4
i will input a number in textbox1 which will be the id column in the database and then when i press the search button it will display the corresponding data based on the id. here's my code

Expand|Select|Wrap|Line Numbers
  1.  strsql = "select * from tbuser where ID = '" & TextBox1.Text & "'"
  2.         sqlcmd.CommandText = strsql
  3.         sqlcmd.Connection = GetConnection1()
  4.         read = sqlcmd.ExecuteReader()
  5.  
  6.         If read.HasRows Then
  7.             While read.Read
  8.  
  9.                 Label2.Text = (read.GetChar(1))
  10.             End While
  11.         End If
  12.         GetConnection1.Close()
  13.  
the error is in
Expand|Select|Wrap|Line Numbers
  1. read = sqlcmd.ExecuteReader()
  2.  
Data type mismatch in criteria expression.
i use ms access for the database and visual studio 2010.
thanks in advance for helping ^_^
Mar 6 '13 #1
Share this Question
Share on Google+
3 Replies


Rabbit
Expert Mod 10K+
P: 12,392
What is the SQL string that is executed (with the variables expanded)?

What is the design of the table?

What is the data type of the read variable?
Mar 6 '13 #2

Mikkeee
P: 94
Generally an ID column in your database will be a numeric data type but you're passing it along as a string by enclosing your sql in single quotes.
Mar 7 '13 #3

P: 5
Expand|Select|Wrap|Line Numbers
  1. vbcon.Open()
  2.             Dim str As String = ""
  3.  
  4.             str = "SELECT * FROM mytablename"
  5.  
  6.  
  7. Dim dbCommand As New SqlCommand(str, vbcon)
  8. Dim dbReader = dbCommand.ExecuteReader
  9.  
  10.  
  11.  While dbReader.Read()
  12.                 textboxtext = dbReader.Item("myvarname")
  13.  End While
  14.             dbReader.Close()
Jun 14 '13 #4

Post your reply

Sign in to post your reply or Sign up for a free account.