tan keng
tan keng

Reputation: 7

connect to SQL using asp.net

anyone can help me to connect to SQL server through vb.net using asp.net webform.. I have the database name Users and i want to use the database for the login page.. please help me..

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim ConnectionString As String 
    ConnectionString = ConfigurationSettings.AppSettings("ConnectionString")
    Dim con As New SqlConnection(ConnectionString) 
    Dim cmd As New SqlCommand("Select UserId, Pwd from Users", con) 
    con.Open()
    Dim myreader As SqlDataReader
    myreader = cmd.ExecuteReader() 
    While myreader.Read()
        If TxtUserId.Text = myreader("UserId").ToString().Trim() 
           AndAlso TxtPwd.Text = myreader("Pwd").ToString().Trim() Then
            Session("UserId") = TxtUserId.Text 
            Response.Redirect("UserMyProfile.aspx") 
        Else 
            lblMsg.Visible = True 
            lblMsg.Text = "Inavalid UserId/Password" 
        End If
    End While
    con.Close() 
End Sub 

Upvotes: 0

Views: 95

Answers (1)

David
David

Reputation: 218798

There's no shortage of tutorials on the web for this, but a good starting point is here.

EDIT: Based on your comments above, it sounds like you're not importing the Namespace you need for the ADO.NET data objects. Try adding this to the class file:

Imports System.Data.SqlClient

Upvotes: 1

Related Questions