[求助]谁能给一个通过ODBC函数读取db的实际例子,多谢了
robot自带的例子看不懂啊connection = SQLOpen("DSN=SblTest", outputStr, prompt:=5)
这个里面的DSN=SblTest是怎么连结数据库的,不懂啊,求教大家了。 在控制面板的管理工具里的数据源配置DSN 明白了,谢谢 我这里有个代码的例子,你可以参考下,很简单!但是完全可以说明问题!
代码如下:
Sub main
' Declarations
'
Dim outputStr As String
Dim connection As Long
Dim prompt As Integer
Dim datasources(1 To 6,1 to 9) As Variant
Dim retcode As Variant
Dim iProcColumns As Integer
Dim iProcRows As Integer
Dim iProcRowCount As Integer
Dim iProcColumnCount As Integer
Dim sFunctionCall As String
prompt = 2
connection = SQLOpen("DSN=RationalTest", outputStr, prompt:=2)
retcode = SQLExecQuery(connection:=connection,query:="select * from product ")
retcode = SQLRetrieve(connection,datasources())
For iProcRowCount = 1 to 10
.
For iProcColumnCount = 1 to 6
sFunctionCall = datasources(iProcRowCount, iProcColumnCount)
Next iProcColumnCount
Next iProcRowCount
retcode = SQLClose(connection)
End Sub 获益非浅~~ Sub main
' Declarations
'
Dim outputStr As String '请问这里定义的变量是干什么啊?
Dim connection As Long
Dim prompt As Integer'请问这里的prompt是什么意思?
Dim datasources(1 To 6,1 to 9) As Variant'这又指什么呢?
Dim retcode As Variant'这是干嘛的?
Dim iProcColumns As Integer
Dim iProcRows As Integer
Dim iProcRowCount As Integer
Dim iProcColumnCount As Integer
Dim sFunctionCall As String
prompt = 2 ’为什么是2?什么意思?
connection = SQLOpen("DSN=RationalTest", outputStr, prompt:=2)
retcode = SQLExecQuery(connection:=connection,query:="select * from product ")
retcode = SQLRetrieve(connection,datasources())
For iProcRowCount = 1 to 10
.
For iProcColumnCount = 1 to 6
sFunctionCall = datasources(iProcRowCount, iProcColumnCount)
Next iProcColumnCount
Next iProcRowCount
retcode = SQLClose(connection)
End Sub
能不能详细讲解一下比较笨呢 这方面的基础比较弱
谢谢 good,同上,不是很明白。 Q:Dim datasources(1 To 6,1 to 9) As Variant'这又指什么呢?
A:定义一个二维数组。即6行9列。 Q: Dim retcode As Variant'这是干嘛的?
A: retcode = SQLExecQuery(connection:=connection,query:="select * from product ")'执行查询
retcode = SQLRetrieve(connection,datasources())'取回结果,结果存入二维数组 hao
页:
[1]