having problem with datareader

dualshock03

Well-known member
Joined
Jan 28, 2007
Messages
105
Programming Experience
1-3
Hi people can anyone fix this code?

My concept here is that when i type a userID in the textbox, the second textbox will generate its corresponding fullname of the certain employee matching to the userID.

VB.NET:
 Private Sub btncalreg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncalreg.Click
        Dim empIDcon As New MySqlConnection("server =localhost; user id=root; password=pat; database=lnupayroll2007")

        Dim empnum As New MySqlCommand("SELECT * FROM regularpayroll2007 WHERE Emp_No. ='" & tremp.Text & "'", empIDcon)
        Dim reader As MySqlDataReader
        empnum.Connection = empIDcon
        empIDcon.Open()
        reader = empnum.ExecuteReader()
        If (reader.Read()) Then
            Dim strempName As String
            strempName = reader("Fullname").ToString()
            trname.Text = strempName
            empIDcon.Close()
        End If

Im recieving an error that says: " #42000You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '='20070001'' at line 1"

The error points to this code:
reader=empnum.ExecuteReader() <-------- is highlighted in yellow


Thanks in advance
 
Read the PQ link in my signature, then read the DW2 link, section "Creating a form to search data"

Note, that because youre using MySQL, you will struggle to follow the DW2 advice exactly, because MySQL doesnt integrate properly with the Visual Studio IDE. You can, however, follow the advice with an access database, then look at the code the IDE has generated and convert it for use with MySQL with a bit of find/replace. Forum member DazlerD has some direct experience with this, as we spent a day recently, hammering about with it. I wasnt actually doing the coding; I was just providing answers and inspiration for when it went wrong. Daz should be able to give you some good advice...

..ps, the good advice that I would give you is; if youre using MySQL because it is free, dont bother - not integrating with the IDE places such a serious restriction on productivity that it actually ends up costing a huge amount more than using SQLServer Express or Oracle Express - both of which are free, and do integrate with the IDE
 
Back
Top