我绑定rs的时候,我不想直接显示数据库中的内容,我想显示程序处理后的数据,但又不用保存到数据库中
With REC
If .State = 1 Then .Close
'.CursorLocation = adUseClient
.Open "select SortID AS 编码, StuffSort AS 材料类别 from wh_StuffSort order by SortID", PCN, adOpenStatic, adLockOptimistic
Do While Not REC.EOF
'Me.Caption = REC.Fields(0)
REC.Fields(1) = REC.Fields(1) + "ning"
REC.MoveNext
Loop
Set VSFlexGrid1.DataSource = REC
End With
这样虽然可以显示修改后的值了,但是它怎么会保存到数据库中呢?我又没有调用update?
我想修改rs中的内容,又不用保存,该怎么做?
With REC
If .State = 1 Then .Close
'.CursorLocation = adUseClient
.Open "select SortID AS 编码, StuffSort AS 材料类别 from wh_StuffSort order by SortID", PCN, adOpenStatic, adLockOptimistic
Do While Not REC.EOF
'Me.Caption = REC.Fields(0)
REC.Fields(1) = REC.Fields(1) + "ning"
REC.MoveNext
Loop
Set VSFlexGrid1.DataSource = REC
End With
这样虽然可以显示修改后的值了,但是它怎么会保存到数据库中呢?我又没有调用update?
我想修改rs中的内容,又不用保存,该怎么做?
'Me.Caption = REC.Fields(0)
debug.print REC.Fields(1) + "ning"
REC.MoveNext
Loop这样才是“显示”,你原来的写法相当于set REC.Fields(1)=REC.Fields(1) + "ning"
如果是和数据库关联的,Update 就会更新到数据库中。可以用无连接记录集——就是取得数据后马上断开和数据库的关联,随你怎么修改都不会影响数据库了。
Set REC = New ADODB.RecordSet '<-推荐每次都新建对象'
With REC
'If .State = 1 Then .Close '<-不推荐重用对象'
.CursorLocation = adUseClient '<-最好显式指定,不同的数据库可能不一致'
.Open "select SortID AS 编码, StuffSort AS 材料类别 from wh_StuffSort order by SortID", PCN, adOpenStatic, adLockOptimistic
Set .Connection = Nothing '<- 无连接的重点'
...