當前位置:編程學習大全網 - 編程語言 - 80分懸賞怎麽用VB連接MYSQL數據庫來編寫登陸界面

80分懸賞怎麽用VB連接MYSQL數據庫來編寫登陸界面

/在模塊裏編寫(新建模塊)

Public comm As New ADODB.Command

Public conn As New ADODB.Connection

Public uname As String

Public pwd As String

Public ulevel As Integer

Sub main()

conn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=wow;Data Source=."

conn.Open

Form1.Show

End Sub

'判斷登陸是否成功(封裝函數)

Public Function isLogin(uname, pwd, ulevel) As Boolean

Dim flag As Boolean

comm.ActiveConnection = conn

comm.CommandType = adCmdStoredProc

comm.CommandText = "isLogin"

comm.Parameters(1).Type = adVarChar

comm.Parameters(1).Size = 50

comm.Parameters(1).Direction = adParamInput

comm.Parameters(1).Value = uname

comm.Parameters(2).Type = adVarChar

comm.Parameters(2).Size = 50

comm.Parameters(2).Direction = adParamInput

comm.Parameters(2).Value = pwd

comm.Parameters(3).Type = adInteger

comm.Parameters(3).Size = 4

comm.Parameters(3).Direction = adParamInput

comm.Parameters(3).Value = ulevel

comm.Parameters(4).Type = adInteger

comm.Parameters(4).Size = 4

comm.Parameters(4).Direction = adParamOutput

comm.Execute

If comm.Parameters(4).Value > 0 Then

flag = True

Else

flag = False

End If

isLogin = flag

End Function

/在登陸窗體中調用封裝函數實現登陸判斷

Private Sub Command1_Click()

Dim uname As String

Dim pwd As String

Dim ulevel As Integer

uname = Text1.Text

pwd = Text2.Text

If Combo1.Text = "管理員" Then

ulevel = 1

Else

ulevel = 0

End If

If isLogin(uname, pwd, ulevel) Then

MsgBox "登陸成功", vbOKOnly, "提示"

Form2.Show

Unload Me

Else

MsgBox "登錄失敗", vbOKOnly, "提示"

End If

End Sub

Private Sub Command2_Click()

Text1.Text = Clear

Text2.Text = Clear

Text1.SetFocus

End Sub

Private Sub Command3_Click()

Unload Me

End Sub

Private Sub Command4_Click()

Form3.Show

Unload Me

End Sub

Private Sub Form_Load()

Combo1.AddItem "管理員"

Combo1.AddItem "用戶"

End Sub

/在MYSQL企業管理器中編寫存儲過程:(選中以下編寫的內容並執行即可生成存儲過程)

create proc isLogin @uname varchar(50), @pwd varchar(50),@ulevel int, @flag int output

as

declare @count int

select @count=count(*) from [user] where

uname=@uname and pwd=@pwd and ulevel=@ulevel

if @count>0

set @flag=1

else

set @flag=0

create proc AddUser @uname

給分把

  • 上一篇:Lucene實戰的目錄
  • 下一篇:微信公眾賬號排行?
  • copyright 2024編程學習大全網