Private Sub Command1_Click()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strCnn As String
Dim snumber As String, a As String, b As String, c As String, d As String, e As String, f As String
'获取用户名和密码
snumber = Trim(Text1.Text)
a = Trim(Text2.Text)
b = Trim(Text3.Text)
c = Trim(Text4.Text)
d = Trim(Text5.Text)
e = Trim(Text6.Text)
f = Trim(Text7.Text)
'设置数据库连接串
strCnn = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\student.mdb"
'sqlserver 设置odbc ole DB
'strCnn = "driver={SQL SERVER);SERVER=zhangsan;UID=sa;PWD=sa;DATABASE=password"
'sqlserver 设置MS SQL SERVER OLD DB数据源连接
'strCnn = "PROVIDER=SQLOLEDB;UID=sa;PWD=sa;Persist"+"security info=false;Initial catalog=password"
'创建连接对象
Set cn = New ADODB.Connection
cn.Open strCnn
'创建comand对象cm
Dim cm As New ADODB.Command
cm.ActiveConnection = cn
'给command对象执行sql命令,带变量的插入语句
cm.CommandText = "update stu set sname='" + a + "',sdept='" + b + "',sex='" + c + "',born='" + d + "',credit='" + e + "',remark='" + f + "' where snumber='" + snumber + "'"
cm.CommandType = adCmdText
cm.CommandTimeout = 15
Set rs = cm.Execute(1, 1, 1)
If cn.Errors.Count = 0 Then
'Text1.Text = rs!usersname
MsgBox ("更改成功")
Else
MsgBox ("无此用户")
End If
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strCnn As String
Dim snumber As String, a As String, b As String, c As String, d As String, e As String, f As String
'获取用户名和密码
snumber = Trim(Text1.Text)
a = Trim(Text2.Text)
b = Trim(Text3.Text)
c = Trim(Text4.Text)
d = Trim(Text5.Text)
e = Trim(Text6.Text)
f = Trim(Text7.Text)
'设置数据库连接串
strCnn = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\student.mdb"
'sqlserver 设置odbc ole DB
'strCnn = "driver={SQL SERVER);SERVER=zhangsan;UID=sa;PWD=sa;DATABASE=password"
'sqlserver 设置MS SQL SERVER OLD DB数据源连接
'strCnn = "PROVIDER=SQLOLEDB;UID=sa;PWD=sa;Persist"+"security info=false;Initial catalog=password"
'创建连接对象
Set cn = New ADODB.Connection
cn.Open strCnn
'创建comand对象cm
Dim cm As New ADODB.Command
cm.ActiveConnection = cn
'给command对象执行sql命令,带变量的插入语句
cm.CommandText = "update stu set sname='" + a + "',sdept='" + b + "',sex='" + c + "',born='" + d + "',credit='" + e + "',remark='" + f + "' where snumber='" + snumber + "'"
cm.CommandType = adCmdText
cm.CommandTimeout = 15
Set rs = cm.Execute(1, 1, 1)
If cn.Errors.Count = 0 Then
'Text1.Text = rs!usersname
MsgBox ("更改成功")
Else
MsgBox ("无此用户")
End If
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub