开发者

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..

开发者_StackOverflowPrivate 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 


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜