VB.net做用户登录界面 一直提示用户名不存在,但是数据库里面有用户名,密码也没错。帮忙看下代码有没有错

Private Sub BtOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtOk.Click

Dim ob_interface As New MainForm

Try

Me.Text = "正在验证……"
Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
Dim comstr As String
Dim mydataset As New DataSet
comstr = "select 密码 from " & CmbPurview.Text & " where 用户名 = ' " & Trim(TxtUserName.Text) & " '"
mydataset.Clear()
Dim adapter As New SqlDataAdapter(comstr, SqlConnection1)
adapter.Fill(mydataset, "table1")
If mydataset.Tables("table1").Rows(0).Item(0) Is Trim(TxtPassword.Text) Then

UserInf(0) = Trim(TxtUserName.Text)
UserInf(1) = CmbPurview.Text
If CmbPurview.Text <> "管理员" Then

With ob_interface

.BtViewInf.Visible = False

.BtClientIfo.Visible = False

End With
End If
ob_interface.Show()
Me.Hide()

Else

MsgBox("密码错误!")

TxtPassword.Text = " "
Me.Text = ""
Me.Cursor = System.Windows.Forms.Cursors.Arrow
TxtPassword.Focus()

End If
Catch ex As Exception

MsgBox("用户名不存在!", MsgBoxStyle.OKOnly, "提示!")

TxtUserName.Text = ""
TxtPassword.Text = ""
Me.Text = ""
Me.Cursor = System.Windows.Forms.Cursors.Arrow

End Try

End Sub

第1个回答  2011-06-22
myconnect.Open()
mycom = New OleDbCommand("SELECT * FROM userset WHERE 登录名='" & txtname.Text & "'AND 密码='" & txtpwd.Text & "'", myconnect)
myadapt = New OleDbDataAdapter
myadapt.SelectCommand = mycom
ds = New DataSet()
myadapt.Fill(ds)
dt = New DataTable
dt = ds.Tables(0)

myconnect.Close()
mycom.Dispose()
If dt.Rows.Count = 1 Then
Return True
Else
If dt.Rows.Count = 0 Then
MsgBox("用户名或密码输入不正确,请重试!", MsgBoxStyle.Exclamation, "提示")
Return False
End If
End If本回答被网友采纳
第2个回答  2011-06-21
应该是没有写入到数据库追问

数据库里面有!

本回答被提问者采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网