VB中如何更改数据库中某个字段的值
VB中如何更改数据库中某个字段的值Dimi,kc,dj,sy,s1,s2,cuslcxct=Text2.TextDimcnAsNewADODB.ConnectionDim...
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)
这段代码没有错误可是为什么就是更改不了字段的值 展开
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)
这段代码没有错误可是为什么就是更改不了字段的值 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询