dim con
set con=createobject("ADODB.Connection")
con.open "driver={sql server}Driver={sql server}uid=用户名pwd=用户密码database=数据库名称server=(local)"
con.execute("你想执行的SQL语句")
/在模块里编写(新建模块)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.1Persist Security Info=FalseUser ID=saInitial Catalog=wowData 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
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)