VB如何对Access数据库中已经查询到的数据进行修改?
点击查询按钮,查询结果显示在Text3中,修改Text3中文本内容【数字】,点击修改按钮,将修改后的Text3中的文本提交到Access中对应的字段"MONEY",表名:...
点击查询按钮,查询结果显示在Text3中,修改Text3中文本内容【数字】,点击修改按钮,将修改后的Text3中的文本提交到Access中对应的字段"MONEY",表名:xjhy
Private Sub Commandxiugai_Click()
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"
'打开数据库连接
conn.Open
sqlStr1 = " update xjhy set MONEY=" & Val(Text3.Text) & " where ID=" & "Text1.text"
rs.Open sqlStr1, conn, 1, 1 【这句老是报错,说是UPDATE 语句错误,求解!】
If Not rs.EOF Then
MsgBox "修改成功!", vbOKOnly
Else
MsgBox "修改失败!", vbOKOnly
End If
End Sub 展开
Private Sub Commandxiugai_Click()
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"
'打开数据库连接
conn.Open
sqlStr1 = " update xjhy set MONEY=" & Val(Text3.Text) & " where ID=" & "Text1.text"
rs.Open sqlStr1, conn, 1, 1 【这句老是报错,说是UPDATE 语句错误,求解!】
If Not rs.EOF Then
MsgBox "修改成功!", vbOKOnly
Else
MsgBox "修改失败!", vbOKOnly
End If
End Sub 展开
3个回答
展开全部
改为如下,用循环方法,先在数据库中找到要修改记录的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
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
展开全部
在值的两侧加上双引号
sqlStr1 = " update xjhy set MONEY=""" & Val(Text3.Text) & """ where ID=" & "Text1.text"
sqlStr1 = " update xjhy set MONEY=""" & Val(Text3.Text) & """ where ID=" & "Text1.text"
追问
依旧语法错误
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
修改为:
sqlStr1 = " update xjhy set MONEY='" & Val(Text3.Text) & "' where ID='" & "Text1.text"'"
再试试
sqlStr1 = " update xjhy set MONEY='" & Val(Text3.Text) & "' where ID='" & "Text1.text"'"
再试试
追问
依旧语法错误!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询