首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

关于登陆的有关问题

2012-02-14 
关于登陆的问题我的数据库名为history,用到的表名为doctor.如果同一个用户连续登陆两次(两次密码都正确或

关于登陆的问题
我的数据库名为history,用到的表名为doctor.
      如果同一个用户连续登陆两次(两次密码都正确或者错误)就会报错: "未处理的“System.InvalidOperationException”类型的异常出现在   system.data.dll   中。
其他信息:   OleDbCommand   是当前正忙的   Open,   Fetching。 "
我是初学者,完全不知道问题出在什么地方,到底怎么才能解决上面这个问题,请高手指教,万分感谢:)

我的代码是这样的:
  Dim   constring   As   String
                Dim   conn   As   New   OleDbConnection
                Dim   cmdst   As   String
                constring   =   "provider   =   sqloledb.1;data   source=zhangying;integrated   security   =   sspi;initial   catalog   =   history "
                conn.ConnectionString   =   constring
                conn.Open()
                If   TextBox1.Text   =   " "   Then
                        MsgBox( "必须输入用户名 ",   MsgBoxStyle.Critical,   "无法登陆 ")
                        TextBox1.Focus()
                        Exit   Sub                          
                End   If
                If   TextBox2.Text   =   " "   Then
                        MsgBox( "必须输入口令 ",   MsgBoxStyle.Critical,   "无法登陆 ")
                        TextBox2.Focus()
                        Exit   Sub
                End   If
                OleDbCmd2.CommandType   =   CommandType.Text

                Try
                        cmdst   =   "select   *   from   doctor   where   doc_name= ' "   +   Trim(TextBox1.Text)   +   " 'and   doc_psw= ' "   +   Trim(TextBox2.Text)   +   " ' "
                        OleDbCmd2.Connection   =   conn
                        OleDbCmd2.CommandText   =   cmdst
                        datard   =   OleDbCmd2.ExecuteReader
                        If   datard.Read   Then
                                MsgBox( "登陆成功 ",   MsgBoxStyle.Exclamation,   "登陆成功 ")
                        Else
                                MsgBox( "用户名或口令不正确 ",   MsgBoxStyle.Critical,   "无法登陆 ")


                                Exit   Sub
                        End   If
                Catch   ex   As   OleDb.OleDbException
                        MsgBox(ex.Message)
                End   Try
                OleDa2.Dispose()
                OleDbCmd2.Dispose()
                Ds21.Dispose()
                conn.Close()




[解决办法]
Dim constring As String
Try
Dim conn As New OleDbConnection
Dim cmdst As String
constring = "provider = sqloledb.1;data source=zhangying;integrated security = sspi;initial catalog = history "
conn.ConnectionString = constring
conn.Open()
If TextBox1.Text = " " Then
MsgBox( "必须输入用户名 ", MsgBoxStyle.Critical, "无法登陆 ")
TextBox1.Focus()
Exit Sub
End If
If TextBox2.Text = " " Then
MsgBox( "必须输入口令 ", MsgBoxStyle.Critical, "无法登陆 ")
TextBox2.Focus()
Exit Sub
End If
OleDbCmd2.CommandType = CommandType.Text
cmdst = "select * from doctor where doc_name= ' " + Trim(TextBox1.Text) + " 'and doc_psw= ' " + Trim(TextBox2.Text) + " ' "
OleDbCmd2.Connection = conn
OleDbCmd2.CommandText = cmdst
datard = OleDbCmd2.ExecuteReader
If datard.Read Then
MsgBox( "登陆成功 ", MsgBoxStyle.Exclamation, "登陆成功 ")
Else
MsgBox( "用户名或口令不正确 ", MsgBoxStyle.Critical, "无法登陆 ")
Exit Sub
End If
Catch ex As OleDb.OleDbException
MsgBox(ex.Message)
Finally
If conn.State = ConnectionState.Open Then
conn.Close()
End If
End Try
[解决办法]
Dim constring As String
Dim conn As New OleDbConnection
Dim cmdst As String
If TextBox1.Text = " " Then
MsgBox( "必须输入用户名 ", MsgBoxStyle.Critical, "无法登陆 ")
TextBox1.Focus()
Exit Sub
End If
If TextBox2.Text = " " Then
MsgBox( "必须输入口令 ", MsgBoxStyle.Critical, "无法登陆 ")
TextBox2.Focus()
Exit Sub
End If

Try

constring = "provider = sqloledb.1;data source=zhangying;integrated security = sspi;initial catalog = history "
conn.ConnectionString = constring
conn.Open()
OleDbCmd2.CommandType = CommandType.Text
cmdst = "select * from doctor where doc_name= ' " + Trim(TextBox1.Text) + " 'and doc_psw= ' " + Trim(TextBox2.Text) + " ' "
OleDbCmd2.Connection = conn
OleDbCmd2.CommandText = cmdst


datard = OleDbCmd2.ExecuteReader
If datard.Read Then
MsgBox( "登陆成功 ", MsgBoxStyle.Exclamation, "登陆成功 ")
Else
MsgBox( "用户名或口令不正确 ", MsgBoxStyle.Critical, "无法登陆 ")
Exit Sub
End If
Catch ex As OleDb.OleDbException
MsgBox(ex.Message)
Finally
If conn.State = ConnectionState.Open Then
conn.Close()
End If
End Try

热点排行