Click here to Skip to main content
15,893,486 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
VB
myconn = New SqlConnection("data source=nic-bpdc;Initial Catalog=pension;integrated security=true;user id=pension;password=admin;")
        myconn.Open()
        cmd.Connection = myconn
        cmd.CommandText = ("select username, password from login where username= '" & TextBox1.Text & "', password= '" & TextBox2.Text & "'")
        dr = cmd.ExecuteReader()

        If dr.HasRows Then

            Main.Show()
            Me.Visible = False
        Else
            MsgBox("invalid username & Password")
Posted

To solve your error replace "', password" with "' AND password"

However, I would also suggest you look at SQL Parameters, your code is vulnerable to SQL injection attacks if you are reading literal strings from text boxes.

I would suggest you have a look at some of these search results:
Google search[^]
 
Share this answer
 
Try this:
C#
cmd.CommandText = ("select username, password from login where username= '"+ TextBox1.Text+  "' and password= '" + TextBox2.Text + "'")
 
Share this answer
 
v3
C#
cmd.CommandText = ("select username, password from login where username= '" + TextBox1.Text + "' AND password= '" + TextBox2.Text + "'");

-KR
 
Share this answer
 
try this..
cmd.CommandText = ("select username, password from login where username= '" & TextBox1.Text & "' and password= '" & TextBox2.Text & "'")
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900