2条记录,如何交换某同一字段的内容(排序),请帮忙看看这两行代码
假设数据表中其中的两条记录
字段1 字段2
11 aa
22 bb
怎么变成
字段1 字段2
22 aa
11 bb
我使用如下语句,测试发现只有第一次有效,第二行的cn.Execute SQL并不执行
(变量已经取得对应值,如a_ID=22,b_ID=11 , a_Type=aa,b_Type=bb)
……
SQL = " update t_DeptType set ID='" & a_ID & " ' where Type='" & b_Type & "'"
cn.Execute SQL
SQL = " update t_DeptType set ID='" & b_ID & " ' where Type='" & a_Type & "'"
cn.Execute SQL
…… --------------------编程问答--------------------
实现功能:列表中选中的列往上移动
完整代码为
If McListBox(0).ListIndex = 0 Then Exit Sub '如果上升排序时,处于列表第一个记录则直接退出
SQL = " select ID,Type from t_DeptType order by ID"
With rs
If .State <> adStateClosed Then .Close
.Open SQL, cn, adOpenStatic, adLockReadOnly
If .RecordCount > 0 Then '如果表中有记录
Dim a_ID As Integer
Dim b_ID As Integer
Dim a_Type As String
Dim b_Type As String
Dim i As Integer
i = McListBox(0).ListIndex ‘取得当前选中的是第几列,第一列值为0,第二列为1……
.MoveFirst
.Move i - 1
a_ID = .Fields("ID")
a_Type = Trim(.Fields("Type"))
If .EOF = False Then
.MoveNext
b_ID = .Fields("ID")
b_Type = Trim(.Fields("Type"))
End If
SQL = " update t_DeptType set ID='" & a_ID & " ' where Type='" & b_Type & "'"
MsgBox SQL
cn.Execute SQL
SQL = " update t_DeptType set ID='" & b_ID & " ' where Type='" & a_Type & "'"
MsgBox SQL
.Close
Else '表中无记录
If .State <> adStateClosed Then .Close
Exit Sub
End If
End With --------------------编程问答-------------------- 没人知道吗 --------------------编程问答-------------------- 没人知道吗 --------------------编程问答-------------------- 先找出来,然后更新
补充:VB , 数据库(包含打印,安装,报表)