VB如何对Access数据库中已经查询到的数据进行修改?

2024-11-07 22:25:45
推荐回答(3个)
回答(1):

改为如下,用循环方法,先在数据库中找到要修改记录的ID后, 再修改。
Private Sub Commandxiugai_Click()
Dim K As Integer
Dim rs As ADODB.Recordset
Dim conn As ADODB.Connection
Dim sqlStr As String

Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\雅颜の小铺会员管理系统\xinjianhy.mdb;Persist Security Info=False"
sqlStr1 = "select * from xjhy”
rs.Open sqlStr1, conn, adOpenKeyset, adLockOptimistic
If Not rs.EOF Then
rs.MoveFirst
End If

For K = 1 To rs.RecordCount
If rs(”ID”)=trim(Text1.text) then
r提交修改s("MONEY”)=Val(Text3.Text)
rs.Update
MsgBox "修改成功!", vbOKOnly
Goto 100
End if
rs.MoveNext
Next K
MsgBox "修改失败!", vbOKOnly

100
Rs.close
Set conn=nothing
End sub

回答(2):

在值的两侧加上双引号
sqlStr1 = " update xjhy set MONEY=""" & Val(Text3.Text) & """ where ID=" & "Text1.text"

回答(3):

修改为:
sqlStr1 = " update xjhy set MONEY='" & Val(Text3.Text) & "' where ID='" & "Text1.text"'"

再试试