CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2011
    Posts
    2

    Exclamation Error in searching a record

    Hi I am receiving an error whenever i search for an ID. i have use input box and here are the code for the search...

    Private Sub cmdSearch_Click()
    Dim key As String, str As String
    key = InputBox("Enter the Student No whose details u want to know: ")
    Set rs = Nothing
    str = "select * from student where ['s_no']= & key"
    rs.Open str, adoconn, adOpenForwardOnly, adLockReadOnly
    txtNo.Text = rs(0)
    txtName.Text = rs(1)
    txtDate.Text = rs(2)
    txtTime.Text = rs(4)
    txtPhone.Text = rs(3)
    txtSection.Text = rs(5)
    Set rs = Nothing
    str = "select * from emp"
    rs.Open str, adoconn, adOpenDynamic, adLockPessimistic
    End Sub

    the ID number should be 8 numbers but whenever i click search i am receiving this error:




    Syntax error (missing operation) in query expression '['s_no']=&key'






    FYI: i am using ms access as my database the field name for the student number is s_no and if you want the full code here it is: PLzz help.. THANKS IN ADVANCE

  2. #2
    Join Date
    May 2009
    Location
    London
    Posts
    51

    Re: Error in searching a record

    Hi, Not sure without knowing the DB layout but probably need to change to....

    str = "SELECT * FROM student WHERE [s_no]= " & key

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured