应用程序的登陆框,老是提示用户不存在,大虾帮忙看看

海大富运动 2005-04-05 09:27:51
Private Sub BtOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtOK.Click
Try
Me.Text = "正在验证...."
Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
Dim comstr As String
Dim mydataset As New DataSet
comstr = "select 密码 from 一般用户 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) = Trim(TxtPassword.Text) Then
'如果查找不到任何行,则此处出现异常
UserInf(0) = Trim(TxtUserName.Text)
UserInf(1) = CmbPurview.Text
If CmbPurview.Text <> "管理员" Then
With ob_MainForm
.BtGoods.Visible = False
.BtFinance.Visible = False
.BtEmployee.Visible = False
.BtSaleHistory.Visible = False
End With
End If
ob_MainForm.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

数据库的结构是 用户名 密码 权限
admin 123456
...全文
315 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
winlmh 2005-04-09
  • 打赏
  • 举报
回复
select 密码 from 一般用户 where 用户名='" & Trim(TxtUserName.Text) & "'"
你根本就沒有讀出用戶名這個字段,改成

select 密码,用戶名 from 一般用户 where 用户名='" & Trim(TxtUserName.Text) & "'"
vb_vs 2005-04-09
  • 打赏
  • 举报
回复
because you dinnot update your datagrid or database

海大富运动 2005-04-08
  • 打赏
  • 举报
回复
谢谢这位大哥了!
fkl711 2005-04-08
  • 打赏
  • 举报
回复
登陆按钮事件
strID = Trim(Me.TextBox1.Text)
If strID = "" Then
Me.Label1.Text = "请输入登录的用户名称。"
Exit Sub
End If
pwd = Trim(Me.TextBox2.Text)
sqlstr = "SELECT * FROM userinf WHERE (user = '" & strID & "')"
DS = New DataSet
DS.Clear()
DS = GetDataFromDB(sqlstr)
If DS.Tables(0).Rows.Count > 0 Then
sqlstr = "SELECT * FROM userinf WHERE " & _
"(user = '" & strID & "') AND (password = '" & pwd & "')"
Dim myDs As DataSet
myDs = New DataSet
myDs.Clear()
myDs = GetDataFromDB(sqlstr)
If myDs.Tables(0).Rows.Count > 0 Then
pepdom = myDs.Tables(0).Rows(0)("qx")
name = strID
‘------启动下一个窗体代码----
Dim frmAbout As New Form2
frmAbout.Show()
'---------------------------
Else
Me.Label1.Text = "输入的密码不正确,请重新输入密码。"
Me.TextBox2.Text = ""
End If
Else
Me.Label1.Text = "查无此人,请确认是否有该用户存在。"
Me.TextBox1.Text = ""
Me.TextBox2.Text = ""
End If
End Sub
海大富运动 2005-04-07
  • 打赏
  • 举报
回复
也没有提示出错!就是开始验证后跳到catch语句提示说没有该用户
海大富运动 2005-04-07
  • 打赏
  • 举报
回复
还有没有人帮忙!
海大富运动 2005-04-07
  • 打赏
  • 举报
回复
不好意思,这么晚才来道谢!不过我不知道怎么调试,我是新手,做了一个断点,也不知道怎么调试!在sql的查询分析器里可以检索出所有数据的
titan90 2005-04-06
  • 打赏
  • 举报
回复
这种情况用DATAREADER合适
hjh1982 2005-04-06
  • 打赏
  • 举报
回复
if mySet.Tables("add").Rows.Count>0 then
看看吧
tl_pear 2005-04-06
  • 打赏
  • 举报
回复
确定一下,是哪一句出错!
Try
Me.Text = "正在验证...."
Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
Dim comstr As String
Dim mydataset As New DataSet
comstr = "select 密码 from 一般用户 where 用户名='" & Trim(TxtUserName.Text) & "'"
mydataset.Clear()
Dim adapter As New SqlDataAdapter(comstr, SqlConnection1)
adapter.Fill(mydataset, "table1") '判断密码是否正确

try

If mydataset.Tables("table1").Rows(0).Item(0).tostring = Trim(TxtPassword.Text) Then
'如果查找不到任何行,则此处出现异常
UserInf(0) = Trim(TxtUserName.Text)
UserInf(1) = CmbPurview.Text
If CmbPurview.Text <> "管理员" Then
With ob_MainForm
.BtGoods.Visible = False
.BtFinance.Visible = False
.BtEmployee.Visible = False
.BtSaleHistory.Visible = False
End With
End If
ob_MainForm.Show()
Catch ex As Exception
MsgBox("用户不存在!", MsgBoxStyle.OKOnly, "提示")
TxtUserName.Text = ""
TxtPassword.Text = ""
Me.Text = ""
Me.Cursor = System.Windows.Forms.Cursors.Arrow

end try
Me.Hide()
Else
MsgBox("密码错误!")
TxtPassword.Text = ""
Me.Text = ""
Me.Cursor = System.Windows.Forms.Cursors.Arrow
TxtPassword.Focus()

End If
Catch ex As Exception
msgbox(ex.message)
Me.Cursor = System.Windows.Forms.Cursors.Arrow

End Try
WTaoboy 2005-04-06
  • 打赏
  • 举报
回复
strSql="select count(*) from [User] where [Username]=@userName";
// string strAccessConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+this.Server.MapPath("PerInfo.mdb");
string strAccessConn = ConfigurationSettings.AppSettings["AccessConnection"]+this.Server.MapPath("PerInfo.mdb");
OleDbConnection AccessCon=new OleDbConnection(strAccessConn);
OleDbCommand comm = new OleDbCommand();
comm.Connection = AccessCon;
comm.Connection.Open();
comm.CommandType = CommandType.Text;
comm.CommandText = strSql;
comm.Parameters.Add("@userName",OleDbType.Char,16);
comm.Parameters["@userName"].Value=Uid.Text.ToString();
comm.ExecuteNonQuery();
if(Convert.ToInt32(comm.ExecuteScalar().ToString())>0)//ExecuteScalar() 返回数据库中第一行第一列的值
{
Uid.Text="";
Pwd.Text="";
PwdOk.Text="";
Page.RegisterStartupScript("msgbox","<script language=javascript>alert('dfgfg')</script>");
}
else
{

}
chinahth 2005-04-06
  • 打赏
  • 举报
回复
你把查询出来的数据绑定到DATAGRID中看看
caicheng 2005-04-05
  • 打赏
  • 举报
回复
还有在这种场合建议使用datareader 而不是dataAdapter以简省系统开销
caicheng 2005-04-05
  • 打赏
  • 举报
回复
跟踪调试一下,确认数据有没有成功的从数据库读出

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧