当前位置: 代码迷 >> VB Dotnet >> 用VB.net链接access数据库做登陆界面,网上的一段代码,运行有异常,求解答
  详细解决方案

用VB.net链接access数据库做登陆界面,网上的一段代码,运行有异常,求解答

热度:54   发布时间:2016-04-25 02:11:44.0
用VB.net链接access数据库做登陆界面,网上的一段代码,运行有错误,求解答?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click
        If txt1.Text = "" Then
            MsgBox("用户名不能为空! 请先输入用户名后再登陆")
            txt1.Focus()
        Else
            Dim cnn As New OleDb.OleDbConnection
            cnn.ConnectionString = "provider=Microsoft.Jet.oledb.4.0;Data source=I:\Software\software\software\Database1.mdb"
            cnn.Open()
            Dim ds As New DataSet
            Dim da As New OleDb.OleDbDataAdapter("select * form [user]", cnn)
            cnn.Close()
            da.Fill(ds, "user")
            If ds.Tables(0).Rows.Count <> 0 Then
                Dim sql As String = "select * form [user] where username=" & Trim(txt1.Text) & ""
                Dim da1 As New OleDb.OleDbDataAdapter(sql, cnn)
                Dim ds1 As New DataSet
                da1.Fill(ds1, "user")
                If ds1.Tables(0).Rows.Count = 0 Then
                    MsgBox("用户名错误!")
                    txt1.Text = ""
                    txt1.Focus()
                Else
                    If txt2.Text = "" Then
                        MsgBox("请输入密码!")
                        txt2.Focus()
                    Else
                        Dim sq2 As String = "select password from user where username=" & Trim(txt1.Text) & " and password=" & Trim(txt2.Text) & ""
                        Dim da2 As New OleDb.OleDbDataAdapter(sql, cnn)
                        Dim ds2 As New DataSet
                        da2.Fill(ds2, "user")
                        If ds2.Tables(0).Rows.Count = 0 Then
                            MsgBox("密码错误!请重新输入密码!")
                            txt2.Text = ""
                            txt2.Focus()
                        Else
                            Me.Hide()
                            detail.ShowDialog()
                        End If
  相关解决方案