最基本的就不说了,其他的一些事关于连接数据库的,我好久没弄了,也只能大概的说下!
Dim 学号, 课程编号, 成绩 As String
学号 = Text1.Text
课程编号 = Text2.Text
成绩 = Text3.Text
Dim rs As New ADODB.Recordset /实例化一个ADO
Dim txtSQL As String
Dim conn As ADODB.Connection
Set conn = New ADODB.Connection /用来连觉数据库的
conn.ConnectionTimeout = 25
conn.Provider = "sqloledb" //用微软提供的OLEDB来连接数据库
conn.Properties("datasource").Value = "1B93A478156D44B" //数据源
conn.Properties("initial catalog").Value = "xscj" /数据库名字
conn.Properties("integrated security").Value = "sspi"
conn.Properties("user id").Value = "sa" /数据库登录名
conn.Open 打开连接数据库
On Error GoTo errh
If Text1.Text = "" Then
MsgBox "不能为空"
If Text2.Text = "" Then
MsgBox "不能为空"
If Text3.Text = "" Then
MsgBox "不能为空"
End If
End If
End If
txtSQL = "select * from xsb where 学号='" & 学号 & "'" 一个SQL语句,用来查询输入的学号
Set rs = New ADODB.Recordset 修改查询到的记录
rs.OpentxtSQL , conn, adOpenKeyset, adLockOptimistic
rs.Fields("学号").Value = Text1.Text
rs.Fields("课程编号").Value = Text2.Text
rs.Fields("成绩").Value = Text3.Text
rs.Update
rs.Close
MsgBox "修改成功!"
Exit Sub
errh:
MsgBox Err.Description