VB中如何更改数据库中某个字段的值

VB中如何更改数据库中某个字段的值
Dim i, kc, dj, sy, s1, s2, cusl
cxct = Text2.Text
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim sql As String
sql = "select * from 商品表 where 编号='" & cxct & "'"
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\数据2.mdb;Persist Security Info=False"
cn.Open
rs.CursorLocation = adUseClient
rs.Open sql, cn, adOpenDynamic, adLockOptimistic
Debug.Print sql
If rs.RecordCount > 0 Then
For i = 0 To rs.Fields.Count - 1
Text3.Text = rs!零售价格
s2 = rs!库存数量
Next i
End If
kc = Val(Text4.Text)
cusl = Val(s2) - Val(kc)
dj = Val(Text3.Text)
sy = dj * kc
s1 = "update 商品表 set 库存数量 = '" & cusl & " ' where 编号='" & cxct & "'"
rs.Close
cn.Close
Text6.Text = Val(Text5.Text) - Val(sy)
这段代码没有错误可是为什么就是更改不了字段的值

你没执行sql语句啊。

rs.Close 前加上

dim rs2 As New ADODB.Recordset
rs2.Open s1, cn, adOpenDynamic, adLockOptimistic
rs2.close
温馨提示:内容为网友见解,仅供参考
第1个回答  2010-06-18
当然了,少了最主要的一句
添加新的话
rs.AddNew

编辑的话
rs.edit

没大仔细看,因该是这样,加在修改之前
相似回答