本帖最后由 meteor0330 于 2014-11-28 14:13 编辑
我设置了一个变量
$RS_Fields='$RS.Fields(0).value & "|" & $RS.Fields(1).value'
我现在想要在GUICtrlSetData中执行它怎么办?
$Item1= GUICtrlCreateListViewItem("|",$ListView1)
GUICtrlSetData($Item1,$RS_Fields)
我这样写完后,执行时,满ListView里都是$RS.Fields(0).value & "|" & $RS.Fields(1).value
并不是我从数据库里读到的数据,我应该怎么办呢?
不知我这样说清楚了没有!
拜托各位大神!!!
我想实现的功能如我3楼所说,
相关函数的源码如下:
Func DaKaiSQL()
Local $conn, $RS
Local $aArr[3]
Local $ListViewBiaoTi
$SQL_IP = GUICtrlRead($Input1) ;SQL服务器名
$SQL_UID = GUICtrlRead($Input2);SQL服务器登录名
$SQL_PW = GUICtrlRead($Input3) ;SQL服务器登录密码
$SQL_Name = GUICtrlRead($Combo1) ;SQL数据库名
$SQL_Table = GUICtrlRead($Combo2) ;SQL表名
$conn = ObjCreate("ADODB.Connection")
$conn.Open("driver={SQL Server};server=" & $SQL_IP & ";uid=" & $SQL_UID & ";pwd=" & $SQL_PW & ";database=" & $SQL_Name)
$RS = ObjCreate("ADODB.Recordset")
$RS.ActiveConnection = $conn
$RS.Open("select column_name,data_type,CHARACTER_MAXIMUM_LENGTH from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = '" & $SQL_Table & "'") ;关键SQL语句,获取表中所有字段的名称、类型和长度
If @error = 0 Then ;判断数据库是否正常连接
If ($RS.Fields(0).value) <> "" Then
Local $i = 0
While Not $RS.eof And Not $RS.bof
If @error = 1 Then ExitLoop
If $i > 0 Then ReDim $ArrZiduan[UBound($ArrZiduan) + 1][3] ;调整二维数组行数
For $j = 0 To 2
$aArr[$j] = $RS.Fields($j).value ;读取单行值赋给一维数组
Next
$ArrZiduan[$i][0] = $aArr[0] ;将一维数组值赋给二维数组
$ArrZiduan[$i][1] = $aArr[1] ;将一维数组值赋给二维数组
$ArrZiduan[$i][2] = $aArr[2] ;将一维数组值赋给二维数组
$RS.movenext
$i = $i + 1
WEnd
;_ArrayDisplay($ArrZiduan);显示数组数据
;下面的循环用于设置ListView的标题
For $k = 0 To UBound($ArrZiduan) - 1
If $k = 0 Then
$ListViewBiaoTi = $ArrZiduan[$k][0]
Else
$ListViewBiaoTi = $ListViewBiaoTi & "|" & $ArrZiduan[$k][0]
EndIf
Next
GUICtrlSetState($ListView2, $GUI_HIDE) ;隐藏程序启动时创建的ListView2
$ListView1 = GUICtrlCreateListView($ListViewBiaoTi, 32, 168, 817, 481) ;创建ListView
Else
GUICtrlSendMsg($ListView1, $LVM_DELETEALLITEMS, 0, 0) ;发送消息,清空listview1控件
_GUICtrlStatusBar_SetText($StatusBar1, "ERROR!!!! 数据库“" & $SQL_Name & "”上没有找到用户表,请检查。", 2)
EndIf
Else
;_GUICtrlStatusBar_SetText($StatusBar1, "ERROR!!!!数据库打开错误。", 2)
EndIf
$conn.Close
$RS.close
EndFunc ;==>DaKaiSQL
Func DuSQL20()
Local $conn, $RS, $Cb1
Local $FenGeFu = ""
;计算“|”的数量
For $k = 0 To UBound($ArrZiduan) - 2
$FenGeFu = $FenGeFu & "|"
Next
;得到$RS.Fields(0).value语句
Local $RS_Fields_value = ""
For $m = 0 To UBound($ArrZiduan) - 1
If $m = 0 Then
$RS_Fields_value = "$RS.Fields(" & $m & ").value"
Else
$RS_Fields_value = $RS_Fields_value & ' & "|" & $RS.Fields(' & $m & ').value'
EndIf
Next
GUICtrlSendMsg($ListView1, $LVM_DELETEALLITEMS, 0, 0) ;发送消息,清空listview1控件
$SQL_IP = GUICtrlRead($Input1) ;SQL服务器名
$SQL_UID = GUICtrlRead($Input2);SQL服务器登录名
$SQL_PW = GUICtrlRead($Input3) ;SQL服务器登录密码
$SQL_Name = GUICtrlRead($Combo1) ;SQL数据库名
$SQL_Table = GUICtrlRead($Combo2) ;SQL表名
$conn = ObjCreate("ADODB.Connection")
$conn.Open("driver={SQL Server};server=" & $SQL_IP & ";uid=" & $SQL_UID & ";pwd=" & $SQL_PW & ";database=" & $SQL_Name)
$RS = ObjCreate("ADODB.Recordset")
$RS.ActiveConnection = $conn
$RS.Open("select TOP 20 * from " & $SQL_Table);读取前20个值
If @error = 0 Then ;判断数据库是否正常连接
While Not $RS.eof And Not $RS.bof
If @error = 1 Then ExitLoop
$Item1 = GUICtrlCreateListViewItem($FenGeFu, $ListView1)
GUICtrlSetData($Item1, $RS_Fields_value)
$RS.movenext
WEnd
Else
_GUICtrlStatusBar_SetText($StatusBar1, "ERROR!!!! 数据库打开错误。", 2)
EndIf
$conn.Close
$RS.close
EndFunc ;==>DuSQL20
现在就是GUICtrlSetData($Item1, $RS_Fields_value)这句有问题!
我应该怎么办呢? |