vb程序设计登陆界面代码详例
Imports System.Data.SqlClient
Public Class frmMagementMain
'Inherits System.Windows.Forms.Form
Dim constr As String = "User ID=sa;pwd=a;Initial Catalog=zbb;Data Source=(local)" '定义一个变量,连接字符串
Dim sqlstr As String = "select * from manid" '定义一个变量,SQL语句
Dim mycon As New SqlConnection(constr) '定义一个变量,为一个连接对象
Dim mycom As New SqlCommand(sqlstr, mycon) '定义一个变量,为命令对象
Dim myReader As SqlDataReader '定义一个变量,阅读器
Dim i As Integer = 0
Dim userIDsys() As Array
Private Sub frmMagementMain_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
mycon.Open() '打开这个联接
myReader = mycom.ExecuteReader '把这个命令的连接送入阅读器
myReader.Read()
Dim k As Integer = 0
While myReader.Read 'while 为遍历集合的每一项,用阅读器的read的方法来读取'定义一个变量的第一项
k = k + 1
'MsgBox(myReader.Item(1))
End While
MsgBox(k)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
' Visual Basic 2005
' Declare a new TextBox.
Dim TextBox2 As New TextBox
' Set the location below the first TextBox
TextBox2.Left = 102
TextBox2.Top = 242
' Add the TextBox to the form's Controls collection.
Me.Controls.Add(TextBox2)
TextBox2.Text = "这可是我动态加的控件呀"
End Sub
Private Sub mnu_magement_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnu_magement.Click
Dim frmlogin As frmlogin = New frmlogin
frmlogin.Show()
'GBmagemetPeple.Left = 8
'GBmagemetPeple.Top = 28
'GBmagemetPeple.Visible = True
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button2.Click
End Sub
End Class
/////////////////////////////////////
Imports System.Data.SqlClient
Public Class frmlogin
Dim i As Integer = 0
Dim constr1 As String = "" '定义一个变量,连接字符串
Dim sqlstr1 As String = ""
Dim mycon1 As New SqlConnection(constr1) '定义一个变量,为一个连接对象
Dim mycom1 As New SqlCommand(sqlstr1, mycon1) '定义一个变量,为命令对象
Dim myReader1 As SqlDataReader '定义一个变量,阅读器
Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles OK_Button.Click
If txtUsename.Text = "" Or txtPassword.Text = "" Then
MsgBox("请输入用户名和密码")
Exit Sub
vb设计模拟密码输入器End If
sqlstr1 = "select * from mgpep where usernameID='" & txtUsename.Text & "' and
passwordID='" & txtPassword.Text & "'" '定义一个变量,SQL语句
constr1 = "User ID=sa;pwd=a;Initial Catalog=SaleCD;Data Source=(local)" '定义一个变量,连接字符串
mycon1.ConnectionString = constr1
mycom1.CommandText = sqlstr1
mycon1.Open() '重新打开这个联接
myReader1 = mycom1.ExecuteReader '第二次把这个命令的连接送入阅读器
If myReader1.VisibleFieldCount = 0 Then
MsgBox("密码不对请重新输入~")
Exit Sub
End If
myReader1.Read() '阅读器重新使用read方法
On Error GoTo ss
If myReader1(0) > 0 Then
frmMagementMain.GBmagemetPeple.Visible = True
sqlstr1 = "select * from mgpep"
If mycon1.State = 1 Then
mycon1.Close()
End If
mycon1.Open()
myReader1 = mycom1.ExecuteReader '把这个命令的连接送入阅读器
Dim userIDsys(myReader1.VisibleFieldCount - 1, 2)
'ReDim userIDsys(10, 2)
Dim k As Integer = 0
While myReader1.Read
frmMagementMain.CmbUser.Items.Add(myReader1(0))
For i = 0 To 2
userIDsys(k, i) = myReader1.Item(i)
Next
k = k + 1
End While
MsgBox("已经成功登录~")
mycon1.Close()
Me.Close()
Exit Sub
Else
MsgBox("您没有权限登录~")
mycon1.Close()
Me.Close()
Exit Sub
End If
ss:
MsgBox("您没有权限登录~")
Me.Close()
End Sub
Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。