如何使用ADO实现UPDATE等查询
编号:QA001850
建立日期: 1999年10月12日 最后修改日期:2002年11月27日
所属类别:
fsf:
vb6
win98
在使用DAO控件时,可这样执行一update语句 (dao.database.execute "update ...)。问如何使用Ado控件实现相同的功能。
回答:
ADODB.Command对象就是用来执行UPDATE等SQL查询语句的,类似于DAO的Execute方法。例如:
Dim cmd As ADODB.Command
Dim strOldCity As String
Dim strNewCity As String
Dim lngRecs As Long
Set cmd = New ADODB.Command
cmd.ActiveConnection = _
"Provider = Microsoft.Jet.OLEDB.3.51; " & _
"Data Source=" & App.Path & "\Mydb.mdb"
cmd.CommandText = _
"UPDATE tblCustomer SET City = ? WHERE City = ?"
strOldCity = InputBox( _
Prompt := "请输入要替换的城市名")
strNewCity = InputBox( _
Prompt := "请输入新城市名")
cmdExecute _
lngRecs, Arrray(strNewCity, strOldCity), adCmdText)
MsgBox "有" & lngRecs & "条记录被修改。"
cansum的意见:
cmd.execute= _
"UPDATE tblCustomer SET City = ? WHERE City = ?"
panfeng的意见:
如果是只要update,那么使用ADO的connection对像的execute方法会更加的节省开销。
此问题由李海回答。
| |
|
|
| |
|
|