使用 asp.net 连接到 SQL

发布于 2024-10-27 04:05:20 字数 963 浏览 5 评论 0原文

任何人都可以帮助我使用asp.net webform通过vb.net连接到SQL服务器..我有数据库名称Users,我想使用该数据库作为登录页面..请帮助我..

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 

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 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

霓裳挽歌倾城醉 2024-11-03 04:05:20

网络上不乏这方面的教程,但这里是一个很好的起点< /a>.

编辑:根据您上面的评论,听起来您没有导入 ADO.NET 数据对象所需的命名空间。尝试将其添加到类文件中:

Imports System.Data.SqlClient

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文