如何用vb将数据写入数据库啊,急急急! 10
2个回答
展开全部
Public Sub update(SQL_cmd As String) '用来执行数据库操作,其中SQL_cmd为SQL命令
On Error GoTo err
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\tl\桌面\study.mdb;Persist Security Info=False" '自己把路径改成你需要的路径
If cn.State = 0 Then cn.Open
' cn.Open '打开连接
Set rs = cn.Execute(SQL_cmd) '执行SQL语句,其中SQL_cmd为SQL命令
cn.Close
Set cn = Nothing
Set rs = Nothing
MsgBox "执行成功"
Exit Sub
err:
Set cn = Nothing
Set rs = Nothing
MsgBox err.Description, vbCritical, "出错了"
End Sub
Private Sub Command1_Click()
Dim SQL_cmd As String
SQL_cmd = "insert into study values ('456i','789')" '改成实际的SQL命令
update SQL_cmd '调用过程
End Sub
On Error GoTo err
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\tl\桌面\study.mdb;Persist Security Info=False" '自己把路径改成你需要的路径
If cn.State = 0 Then cn.Open
' cn.Open '打开连接
Set rs = cn.Execute(SQL_cmd) '执行SQL语句,其中SQL_cmd为SQL命令
cn.Close
Set cn = Nothing
Set rs = Nothing
MsgBox "执行成功"
Exit Sub
err:
Set cn = Nothing
Set rs = Nothing
MsgBox err.Description, vbCritical, "出错了"
End Sub
Private Sub Command1_Click()
Dim SQL_cmd As String
SQL_cmd = "insert into study values ('456i','789')" '改成实际的SQL命令
update SQL_cmd '调用过程
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询