vb 中如何往access数据库中添加1条新记录,又如何删除呢请写程序命令
DimConn,RecoSetConn=CreateObject("ADODB.Connection")SetReco=CreateObject("ADODB.Recor...
Dim Conn, Reco
Set Conn = CreateObject("ADODB.Connection")
Set Reco = CreateObject("ADODB.Recordset")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\MyWorks\vb\main.mdb;Persist Security Info=False"
Reco.Open "insert into myuse values('0001','0004')
----提示我说insert into命令语法错误 请问错在那了?
如何删除啊 ????命令 展开
Set Conn = CreateObject("ADODB.Connection")
Set Reco = CreateObject("ADODB.Recordset")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\MyWorks\vb\main.mdb;Persist Security Info=False"
Reco.Open "insert into myuse values('0001','0004')
----提示我说insert into命令语法错误 请问错在那了?
如何删除啊 ????命令 展开
2个回答
展开全部
Dim conn As ADODB.Connection
Dim rs As New ADODB.Recordset
Dim sql As String
Set conn = CreateObject("adodb.connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path + "\dat.mdb" & ";Jet OLEDB:Database Password=123" '打开数据源
sql = "select * from 学生信息 "
rs.CursorLocation = adUseClient
rs.Open sql, conn, adOpenKeyset, adLockPessimistic
'rs.MoveLast
rs.AddNewrs.Fields(0).Value = "李"
rs.Fields(1).Value = 22
rs.Fields(2).Value = "男"
rs.Fields(3).Value = #6/8/1984#
rs.Update
rs.Close
conn.Close
Set conn = CreateObject("adodb.connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path + "\dat.mdb" & ";Jet OLEDB:Database Password=123" '打开数据源
sql = "select * from 学生信息 "
rs.CursorLocation = adUseClient
rs.Open sql, conn, adOpenKeyset, adLockPessimistic
rs.Move Label9
If MsgBox("你确定要删除姓名为:" & rs.Fields(0) & " 记录吗?", 1 + 32 + 0) = vbOK Then
rs.Delete
rs.Update
End If
rs.Close
conn.Close
Dim rs As New ADODB.Recordset
Dim sql As String
Set conn = CreateObject("adodb.connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path + "\dat.mdb" & ";Jet OLEDB:Database Password=123" '打开数据源
sql = "select * from 学生信息 "
rs.CursorLocation = adUseClient
rs.Open sql, conn, adOpenKeyset, adLockPessimistic
'rs.MoveLast
rs.AddNewrs.Fields(0).Value = "李"
rs.Fields(1).Value = 22
rs.Fields(2).Value = "男"
rs.Fields(3).Value = #6/8/1984#
rs.Update
rs.Close
conn.Close
Set conn = CreateObject("adodb.connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path + "\dat.mdb" & ";Jet OLEDB:Database Password=123" '打开数据源
sql = "select * from 学生信息 "
rs.CursorLocation = adUseClient
rs.Open sql, conn, adOpenKeyset, adLockPessimistic
rs.Move Label9
If MsgBox("你确定要删除姓名为:" & rs.Fields(0) & " 记录吗?", 1 + 32 + 0) = vbOK Then
rs.Delete
rs.Update
End If
rs.Close
conn.Close
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你用的是全角括号,要改过来
Reco.Open "insert into myuse values('0001','0004')"
插入
RunTrans "insert into myuse values('0001','0004')",Conn
删除
RunTrans "delete from myuse where id='0001'",Conn
Public Function RunTrans(ByVal tranSql As String, ByVal AdoConn As Object)
With AdoConn
.BeginTrans
.Execute tranSql
.CommitTrans
End With
End Function
Reco.Open "insert into myuse values('0001','0004')"
插入
RunTrans "insert into myuse values('0001','0004')",Conn
删除
RunTrans "delete from myuse where id='0001'",Conn
Public Function RunTrans(ByVal tranSql As String, ByVal AdoConn As Object)
With AdoConn
.BeginTrans
.Execute tranSql
.CommitTrans
End With
End Function
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询