请教ADO更新数据问题

skydg 2001-08-05 11:28:57
修改数据时为什么会新增一条而不是更改原来的数据?
我并没有用rs.AddNew,代码如下:

Dim SQL As String
SQL = "select * from 档案 Order by 学号"
rs.Open SQL, conn, adOpenStatic, adLockOptimistic

rs!姓名 = txtFields(2).Text & ""
rs.Update


...全文
115 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiongqj 2001-08-10
  • 打赏
  • 举报
回复
不妨追踪一下,看是否确实找到了要找的纪录.
Dim SQL As String
SQL = "select * from 档案 Order by 学号"
rs.Open SQL, conn, adOpenStatic, adLockOptimistic

debug.print rs.recordcount
debut.print rs("学号")

rs!姓名 = txtFields(2).Text & ""
rs.Update


skydg 2001-08-06
  • 打赏
  • 举报
回复
to outer2000:
rs!姓名 = txtFields(2).Text & ""
只是其中一个,程序里最少有20个要改呀
wyzegg 2001-08-06
  • 打赏
  • 举报
回复
Dim rstEmployees As ADODB.Recordset
Dim strOldFirst As String
Dim strOldLast As String
Dim strMessage As String

' Open recordset with names from Employee table.
strCnn = "driver={SQL Server};server=srv;" & _
"uid=sa;pwd=;database=pubs"
Set rstEmployees = New ADODB.Recordset
rstEmployees.CursorType = adOpenKeyset
rstEmployees.LockType = adLockOptimistic
rstEmployees.Open "SELECT fname, lname " & _
"FROM Employee ORDER BY lname", strCnn, , , adCmdText

' Store original data.
strOldFirst = rstEmployees!fname
strOldLast = rstEmployees!lname
' Change data in edit buffer.
rstEmployees!fname = "Linda"
rstEmployees!lname = "Kobara"

' Show contents of buffer and get user input.
strMessage = "Edit in progress:" & vbCr & _
" Original data = " & strOldFirst & " " & _
strOldLast & vbCr & " Data in buffer = " & _
rstEmployees!fname & " " & rstEmployees!lname & vbCr & vbCr & _
"Use Update to replace the original data with " & _
"the buffered data in the Recordset?"

If MsgBox(strMessage, vbYesNo) = vbYes Then
rstEmployees.Update
Else
rstEmployees.CancelUpdate
End If

' Show the resulting data.
MsgBox "Data in recordset = " & rstEmployees!fname & " " & _
rstEmployees!lname

' Restore original data because this is a demonstration.
If Not (strOldFirst = rstEmployees!fname And _
strOldLast = rstEmployees!lname) Then
rstEmployees!fname = strOldFirst
rstEmployees!lname = strOldLast
rstEmployees.Update
End If

rstEmployees.Close
是不是和你的adOpenStatic有关呀

outer2000 2001-08-06
  • 打赏
  • 举报
回复
update,sorry
outer2000 2001-08-06
  • 打赏
  • 举报
回复
why not use "select * from your tablename set yourrow=yourvalue"
sssoft 2001-08-06
  • 打赏
  • 举报
回复
移动到需要修改的纪录
rs.movefirst
或者rs.move curRow
阿鹏兄 2001-08-06
  • 打赏
  • 举报
回复
up
skydg 2001-08-05
  • 打赏
  • 举报
回复
up

7,789

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧