用vb.net做个登录界面
Imports System.Data.SqlClientImports
Module DataSql
Public UserFlag As Boolean
Public User As String
Public UserID As String
Public UserRight As Int16
Public SqlCon As New SqlConnection("Data Source=10.10.163.225;Database=STUDENT;User Id=SAM;Pwd=SAM")
Public Function GetDataTable(ByVal sql As String) As DataTable
Dim dt As New DataTable
Try
Dim SqlAda As New SqlDataAdapter(New SqlCommand(sql, SqlCon))
SqlAda.Fill(dt)
Catch ex As Exception
WriteErr(ex)
End Try
Return dt
End Function
Public Sub WriteErr(ByVal ex As Exception)
Dim path As String = Application.StartupPath + "\Err01.txt"
If Not File.Exists(path) Then
File.Create(path)
End If
Dim sw As StreamWriter = File.AppendText(path)
sw.Write(System.DateTime.Now.ToString() + vbCrLf)
sw.Write(ex.Message + vbCrLf)
sw.Write(ex.StackTrace + vbCrLf)
sw.Flush()
sw.Close()
End Sub
End Module
上面是添加的DataSql控件,下面是登录界面的源码
Public Class LOGIN
Public flag = False
Private Sub btok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btok.Click
If Me.tbname.Text.Trim() = String.Empty Then
MessageBox.Show("姓名不能为空")
Me.tbname.Focus()
ElseIf Me.tbpwd.Text.Trim() = String.Empty Then
MessageBox.Show("密码不能为空")
Me.tbpwd.Focus()
Else
Dim sql As String = "SELECT * FROM USERINFO WHERE USERID = '" + Me.tbname.Text.Trim() + "' AND USERPWD = '" + Me.tbpwd.Text.Trim() + "'"
Dim dt As DataTable = GetDataTable(sql)
If dt.Rows.Count = 0 Then
MessageBox.Show("用户名不存在或密码不正确")
Me.tbpwd.Focus()
Else
UserRight = dt.Rows(0)("usertype")
UserID = Me.tbname.Text.Trim()
flag = True
Me.Close()
End If
End If
End Sub
Private Sub btcancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btcancel.Click
Application.Exit()
End Sub
End Class
在调试之后,就会出现下面的一些语句:
“DefaultDomain”: 已加载“c:\windows\\framework\v1.1.4322\mscorlib.dll”,未加载符号。
“登录”: 已加载“c:\windows\assembly\gac\mscorlib.resources\1.0.5000.0_zh-chs_b77a5c561934e089\mscorlib.resources.dll”,未加载符号。
“登录”: 已加载“G:\1\登录\bin\登录.exe”,符号已加载。
“登录.exe”: 已加载“c:\windows\assembly\gac\system.windows.forms\1.0.5000.0__b77a5c561934e089\system.windows.forms.dll”,未加载符号。
“登录.exe”: 已加载“c:\windows\assembly\gac\system\1.0.5000.0__b77a5c561934e089\system.dll”,未加载符号。
“登录.exe”: 已加载“c:\windows\assembly\gac\system.drawing\1.0.5000.0__b03f5f7f11d50a3a\system.drawing.dll”,未加载符号。
“登录.exe”: 已加载“c:\windows\assembly\gac\microsoft.visualbasic\7.0.5000.0__b03f5f7f11d50a3a\microsoft.visualbasic.dll”,未加载符号。
“登录.exe”: 已加载“c:\windows\assembly\gac\system.data\1.0.5000.0__b77a5c561934e089\system.data.dll”,未加载符号。
“登录.exe”: 已加载“c:\windows\assembly\gac\system.xml\1.0.5000.0__b77a5c561934e089\system.xml.dll”,未加载符号。
“登录.exe”: 已加载“c:\windows\assembly\gac\system.enterpriseservices\1.0.5000.0__b03f5f7f11d50a3a\system.enterpriseservices.dll”,未加载符号。
“登录.exe”: 已加载“c:\windows\assembly\gac\system.enterpriseservices\1.0.5000.0__b03f5f7f11d50a3a\system.enterpriseservices.thunk.dll”,未加载符号。
程序“[3256] 登录.exe”已退出,返回值为 0 (0x0)。
谢谢多位,现在在做课程设计,很急用。