我正在尝试使用记录集更新 sql 中的单个记录我正在从一个记录集中提取数据并尝试将其保存到数据库中的另一个表这是我的插入语句在 SQL 中运行良好的代码。
' Opening the connection
cn.ConnectionString = "Provider=SQLOLEDB; Data Source=" & dbLocation & "; Initial Catalog=Posbdat; User Id=sa"
cn.Open
rh.ConnectionString = "Provider=SQLOLEDB; Data Source=" & dbLocation & "; Initial Catalog=Postrans; User Id=sa"
rh.Open
rs.Open "Select Top 1 * from CustomerPoints order by RedemptionDate desc", cn, adModeReadWrite
x.Open " Select Top 1 * from Register_Header order by datetime desc", rh, adModeReadWrite
rt.Open " SELECT top 1 upc FROM Register_Trans INNER JOIN Register_Header ON Register_Trans.trans_no = Register_Header.trans_no Where trans_subtype = 'AP' Order by Register_Trans.datetime desc ", rh, adOpenDynamic
Debug.Print x!emp_no
Debug.Print x!till_no
Debug.Print x.Fields(10)
Debug.Print itemupc
itemupc = rt.Fields(0)
Dim cmd As New ADODB.Recordset
cmd.Open "UPDATE CustomerPoints set emp_no = " & x!emp_no & _
", till_no = " & x!till_no & " purch_amt = " & x!Total & _
", item_redeem = ' " & itemupc & " ' Where RedemptionDate = (Select top 1 * from CustomerPoints order by " & _
"RedemptionDate Desc)", cn, adOpenDynamic
cmd.update
我没有关闭任何连接或清理它,因为它不会在不崩溃的情况下运行。