简单的数据库问题,大家帮忙啊

Cell 2005-04-28 11:04:48
下面是一段简单的添加数据库记录的代码,没有错误提示,就是添加记录不成功.数据库应该没问题,是ACCESS的库

Dim sLink As String
Dim RsType As New ADODB.Recordset, rsName As New ADODB.Recordset
Dim sString As String

sLink = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=tjk.mdb;Mode=ReadWrite|Share Deny None;Persist Security Info=False"
If g_dbOpened = False Then
Set g_adoCon = New ADODB.Connection
g_adoCon.Open sLink
g_dbOpened = True
End If
sString = "select * from cb08"
RsType.Source = sString
RsType.Open , g_adoCon, adOpenKeyset, adLockOptimistic, adCmdText
RsType.MoveLast'有没有这句都无法添加
RsType.AddNew
RsType.Fields("DM") = "890000"
RsType.Fields("MC") = "adsfadfy"
RsType.Update
...全文
109 点赞 收藏 10
写回复
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiao1u 2005-05-06
Dim sLink As String
Dim sString As String
Dim g_adoCon As New ADODB.Connection
Dim RsType As New ADODB.Recordset
sLink = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\tools\web\SqlIn.mdb;Mode=ReadWrite|Share Deny None;Persist Security Info=False"
g_adoCon.ConnectionString = sLink
g_adoCon.Open
sString = "select * from abc where 1<>1"
RsType.Source = sString
RsType.ActiveConnection = g_adoCon
RsType.Open sString, , , adLockOptimistic
RsType.AddNew
RsType.Fields("aaa") = "890000"
RsType.Fields("bbb") = "adsfadfy"
RsType.Update
RsType.Close
Set RsType = Nothing
g_adoCon.Close
Set g_adoCon = Nothing
回复
byhum 2005-05-06
你这样写肯定不成功,执行的是select的语句啊
把 sString = "select * from cb08"
RsType.Source = sString
RsType.Open , g_adoCon, adOpenKeyset, adLockOptimistic, adCmdText
去掉,或者换成insert语句,就行了
回复
vbman2003 2005-05-06
RsType.Open , g_adoCon, adOpenKeyset, adLockOptimistic, adCmdText
改为:
RsType.Open sString, g_adoCon, adOpenKeyset, adLockOptimistic
回复
therockdelt 2005-04-29
RsType.Open sString, g_adoCon,adOpenKeyset,dLockOptimistic, adCmdText
回复
zyfire88 2005-04-29
RsType.Open ,sString, g_adoCon, adOpenDynamic, adLockOptimistic, -1
回复
Cell 2005-04-29
RsType.Open , g_adoCon, adOpenDynamic, adLockOptimistic, adCmdText
这样的话回提示没有SQL语句的啊
回复
SmokerX 2005-04-29
RsType.Open , g_adoCon, adOpenDynamic, adLockOptimistic, adCmdText
回复
Cell 2005-04-29
Up,还是不行啊
回复
frankwong 2005-04-28
Dim sLink As String
Dim RsType As New ADODB.Recordset, rsName As New ADODB.Recordset
Dim sString As String

sLink = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=tjk.mdb;Mode=ReadWrite|Share Deny None;Persist Security Info=False"
If g_dbOpened = False Then
Set g_adoCon = New ADODB.Connection
g_adoCon.Open sLink
g_dbOpened = True
End If
sString = "select * from cb08"
'RsType.Source = sString
RsType.Open sString,adOpenKeyset,dLockOptimistic,g_adoCon
'RsType.MoveLast'有没有这句都无法添加
RsType.AddNew
RsType.Fields("DM") = "890000"
RsType.Fields("MC") = "adsfadfy"
RsType.Update
回复
饮水需思源 2005-04-28
'这样试试:
Dim sLink As String
Dim RsType As New ADODB.Recordset, rsName As New ADODB.Recordset
Dim sString As String

sLink = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=tjk.mdb;Mode=ReadWrite|Share Deny None;Persist Security Info=False"
If g_dbOpened = False Then
Set g_adoCon = New ADODB.Connection
g_adoCon.Open sLink
g_dbOpened = True
End If
g_adocon.execute "insert into cb08(dm,mc) values('890000','adsadfy')"
回复
发动态
发帖子

1180

社区成员

VB 数据库(包含打印,安装,报表)
申请成为版主
社区公告
暂无公告