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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Princess Zai
    New Member
    • Mar 2013
    • 4

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

    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

    Code:
     strsql = "select * from tbuser where ID = '" & TextBox1.Text & "'"
            sqlcmd.CommandText = strsql
            sqlcmd.Connection = GetConnection1()
            read = sqlcmd.ExecuteReader()
    
            If read.HasRows Then
                While read.Read
    
                    Label2.Text = (read.GetChar(1))
                End While
            End If
            GetConnection1.Close()
    the error is in
    Code:
    read = sqlcmd.ExecuteReader()
    Data type mismatch in criteria expression.
    i use ms access for the database and visual studio 2010.
    thanks in advance for helping ^_^
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    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?

    Comment

    • Mikkeee
      New Member
      • Feb 2013
      • 94

      #3
      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.

      Comment

      • Nightraven
        New Member
        • Feb 2013
        • 5

        #4
        Code:
        vbcon.Open()
                    Dim str As String = ""
                   
                    str = "SELECT * FROM mytablename"
        
        
        Dim dbCommand As New SqlCommand(str, vbcon)
        Dim dbReader = dbCommand.ExecuteReader
        
        
         While dbReader.Read()
                        textboxtext = dbReader.Item("myvarname")
         End While
                    dbReader.Close()
        Last edited by Rabbit; Jun 14 '13, 03:23 PM. Reason: Please use code tags when posting code.

        Comment

        Working...