“项目”-“添加模块”:
Module Variable
Public User As string
Public UserNAME As string
End Module
然后登陆的时候给 User 赋值
--------------------编程问答--------------------
Private Sub Button_login_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_login.Click
If TextBox_user.Text.Trim = "" Then
MsgBox("用户名不能为空!", MsgBoxStyle.Critical, "错误")
TextBox_user.Focus()
Exit Sub
End If
If TextBox_pwd.Text.Trim = "" Then
MsgBox("密码不能为空!", MsgBoxStyle.Critical, "错误")
TextBox_pwd.Focus()
Exit Sub
End If
Dim sql As String
Dim myconn As Odbc.OdbcConnection = New Odbc.OdbcConnection
myconn.ConnectionString = odbcProductString
Dim mycomm As Odbc.OdbcCommand = New Odbc.OdbcCommand
mycomm.Connection = myconn
Dim myreader As Odbc.OdbcDataReader
Try
sql = "select 用户名,真实姓名,密码 from 用户基本信息表 where 用户名='" + TextBox_user.Text.Trim + "' and 密码='" + TextBox_pwd.Text.Trim + "'"
mycomm.CommandText = sql
myconn.Open()
myreader = mycomm.ExecuteReader
If Not myreader.HasRows Then
MsgBox("用户名或密码错!", MsgBoxStyle.Critical, "错误")
Exit Sub
End If
myreader.Read()
当前用户 = myreader.GetString(0).Trim
当前用户姓名 = myreader.GetString(1).Trim
用户密码 = myreader.GetString(2).Trim
Me.Hide()
主窗体对象.ShowDialog() '显示主窗体
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
End Sub
这是登录窗口的代码,给user赋值要怎么弄?
还有我要调用的用户ID是在另外一个程序中的,是不是要将赋值后的内容存入数据库?
--------------------编程问答--------------------
你把
If myreader.Read = ture Then
USER = myreader("用户名")
……
……
else
MsgBox("用户名或密码错!", MsgBoxStyle.Critical, "错误")
Exit Sub
End If