前台用powerbuilder就可以做到. 因為它支持嵌入式SQL string strName[]; int i = 1; declare mycursor cursor for select name from mytable where age>20; open mycursor; fetch mycursor into :str1; do while sqlca.sqlcode = 0 strName[i] = str1; i++; fetch mycursor into :str1; loop close mycursor;
vb和vc都可以 参见getrow()函数
GetRows here is an example from MSDN: 'BeginGetRowsVB 'To integrate this code 'replace the data source and initial catalog values 'in the connection string
Public Sub GetRowsX() ' connection and recordset variables Dim rstEmployees As ADODB.Recordset Dim Cnxn As ADODB.Connection Dim strSQLEmployees As String Dim strCnxn As String ' array variable Dim arrEmployees As Variant ' detail variables Dim strMessage As String Dim intRows As Integer Dim intRecord As Integer ' open connection Set Cnxn = New ADODB.Connection strCnxn = "Provider=sqloledb;Data Source=MyServer;Initial Catalog=Pubs;User Id=sa;Password=; " Cnxn.Open strCnxn ' open recordset client-side to enable RecordCount Set rstEmployees = New ADODB.Recordset strSQLEmployees = "SELECT fName, lName, hire_date FROM Employee ORDER BY lName" rstEmployees.Open strSQLEmployees, Cnxn, adOpenStatic, adLockReadOnly, adCmdText ' get user input for number of rows strMessage = "Enter number of rows to retrieve:" intRows = Val(InputBox(strMessage))
' if bad user input exit the loop If intRows <= 0 Then MsgBox "Please enter a positive number", vbOKOnly, "Not less than zero!" ' if number of requested records is over the total ElseIf intRows > rstEmployees.RecordCount Then MsgBox "Not enough records in Recordset to retrieve " & intRows & " rows.", _ vbOKOnly, "Over the available total" End If
' else put the data in an array and print arrEmployees = rstEmployees.GetRows(intRows)
Dim x As Integer, y As Integer
For x = 0 To intRows - 1 For y = 0 To 2 Debug.Print arrEmployees(y, x) & " "; Next y Debug.Print vbCrLf Next x
' clean up rstEmployees.Close Cnxn.Close Set rstEmployees = Nothing Set Cnxn = NothingEnd Sub 'EndGetRowsVB
其实,在PB中的返回的结果集,就类似你的数组了, 只是存储结构不同而已
其它语言中的 RecordSet也类似,你在结构集中前后移动不就可以做你想做的时了吗?
如果你非要放到数据里,那就做个循环吧!
因為它支持嵌入式SQL
string strName[];
int i = 1;
declare mycursor cursor for select name from mytable where age>20;
open mycursor;
fetch mycursor into :str1;
do while sqlca.sqlcode = 0
strName[i] = str1;
i++;
fetch mycursor into :str1;
loop
close mycursor;
参见getrow()函数
here is an example from MSDN:
'BeginGetRowsVB 'To integrate this code
'replace the data source and initial catalog values
'in the connection string
Public Sub GetRowsX() ' connection and recordset variables
Dim rstEmployees As ADODB.Recordset
Dim Cnxn As ADODB.Connection
Dim strSQLEmployees As String
Dim strCnxn As String
' array variable
Dim arrEmployees As Variant
' detail variables
Dim strMessage As String
Dim intRows As Integer
Dim intRecord As Integer ' open connection
Set Cnxn = New ADODB.Connection
strCnxn = "Provider=sqloledb;Data Source=MyServer;Initial Catalog=Pubs;User Id=sa;Password=; "
Cnxn.Open strCnxn ' open recordset client-side to enable RecordCount
Set rstEmployees = New ADODB.Recordset
strSQLEmployees = "SELECT fName, lName, hire_date FROM Employee ORDER BY lName"
rstEmployees.Open strSQLEmployees, Cnxn, adOpenStatic, adLockReadOnly, adCmdText ' get user input for number of rows
strMessage = "Enter number of rows to retrieve:"
intRows = Val(InputBox(strMessage))
' if bad user input exit the loop
If intRows <= 0 Then
MsgBox "Please enter a positive number", vbOKOnly, "Not less than zero!"
' if number of requested records is over the total
ElseIf intRows > rstEmployees.RecordCount Then
MsgBox "Not enough records in Recordset to retrieve " & intRows & " rows.", _
vbOKOnly, "Over the available total"
End If
' else put the data in an array and print
arrEmployees = rstEmployees.GetRows(intRows)
Dim x As Integer, y As Integer
For x = 0 To intRows - 1
For y = 0 To 2
Debug.Print arrEmployees(y, x) & " ";
Next y
Debug.Print vbCrLf
Next x
' clean up
rstEmployees.Close
Cnxn.Close
Set rstEmployees = Nothing
Set Cnxn = NothingEnd Sub
'EndGetRowsVB