以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  【登录验证】登录按钮事件代码 运行效率低……麻烦老师们看看是否可以更加简洁 高效  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=160012)

--  作者:cnsjroom
--  发布时间:2021/1/17 17:11:00
--  【登录验证】登录按钮事件代码 运行效率低……麻烦老师们看看是否可以更加简洁 高效
新建一窗体,有使用单位 用户名 密码  数据库源 四个输入框  有一个确定按钮   
输入四项内容之后,点确定按钮进行登录,主窗体至少需要5秒以上才能打开,麻烦各位老师看看是不是这个确定按钮代码有问题  看看有没有优化 更加简便及优化

主窗体默认加载事件代码为空  窗体中也没有任何需要加载的数据表
确定按钮事件代码如下:(想实现当username password  所在单位  三个值在systemuser表里面对应的数据 吻合后才允许打开主窗体)

Dim UserName As String = e.Form.Controls("UserName").Value
Dim cmd As New SQLCommand
Dim dt As DataTable
Dim dr As DataRow
cmd.ConnectionName = _DATA
If UserName = ""  Then
    Messagebox.show("请选择用户!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
    Return
End If
cmd.CommandText = "Sel ect * From {systemuser} Where [username] = \'" & UserName & "\'"
dt = cmd.ExecuteReader
If dt.DataRows.Count = 0 Then
    Messagebox.show("此用户不存在!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
    Return
End If
dr = dt.DataRows(0)
If e.Form.Controls("PassWord").Value = dr("Password") And e.Form.Controls("ComboBox1").Value = dr("所在单位") Then
    _UserName = UserName
    _UserGroup = dr("所在单位")
    _DATA=e.Form.Controls("ComboBox2").Value
    vars("单位")=dr("所在单位")
    e.Form.Close
    Forms("主窗口").show
Else
    Messagebox.show("所在单位或密码输入错误!,请核查!","温馨提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
End If

--  作者:有点蓝
--  发布时间:2021/1/17 20:50:00
--  
这个代码不应该有什么问题。具体请上传实例测试一下