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

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,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.