i had created login form in vb.net
there are two fields username & password.i want to check username & password enter in the login form,from the first.mdf(database file). if it is correct then message is displayed
i had written code for this but i got error in the code.what modification require please reply the code.
* the code of login form is below:

Imports System.Data.SqlClient
Imports System.Data.SqlClient.SqlConnection
Imports System.Data.SqlClient.SqlCommand
Public Class Login
Inherits System.Windows.Forms.Form
Private Sub Login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim u_name As String
Dim pwd As String
u_name = Me.TextBox1.Text
pwd = Me.TextBox2.Text
Dim con As SqlConnection = New SqlConnection("Server=.\SQLExpress;AttachDbFilename=FirstDataSet;Database=First.mdf; Trusted_Connection=Yes;")
Dim cmd As New SqlCommand("SELECT * FROM Reg WHERE userid = 'u_name' AND password = 'pwd' ", con)
Dim sdr As SqlDataReader = cmd.ExecuteReader()
' If the record can be queried, it means passing verification, then open another form.
If (sdr.Read() = True) Then
MessageBox.Show("The user is valid!")
Dim main As New Main
MessageBox.Show("Invalid username or password!")
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ok.Click

End Sub
'close application
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cancel.Click
End Sub
End Class

7 Years
Discussion Span
Last Post by hericles

I'm guessing it is here:
"SELECT * FROM Reg WHERE userid = 'u_name' AND password = 'pwd' "

You aren't inserting the values of u_name and pwd here, you are inserting the text strings u_name and pwd.
You need this:

"SELECT * FROM Reg WHERE userid = '" & u_name & "' AND password = '" & pwd & "' "

Hope that helps,

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.