kyo_zy 发表于 2008-3-14 17:56:23

Rational Robot 对oracle数据库的测试

我需要写个函数对从oracle取出某个表的数据,
然后把数据写到excel文件里,请问各位高手这个函数该怎么写?
希望能有人解决此问题,谢谢。。

geniar 发表于 2008-3-14 20:42:56

贴个例子给你看下:(你可以用SQLGetSchema函数)
This example opens the data source named "SblTest," gets the names in the ODBC data sources, and closes the connection.
Sub main
'   Declarations
'
    Dim outputStr As String
    Dim connection As Long
    Dim prompt As Integer
    Dim datasources(1 To 50) As Variant
    Dim retcode As Variant
    Dim action1 as Integer
    Dim qualifier as String
         
    prompt = 5
'   Open the datasource "SblTest"
    connection = SQLOpen("DSN=SblTest", outputStr, prompt:=5)

    action1 = 1' Get the names of the ODBC datasources
    retcode = SQLGetSchema(connection:=connection,action:=1, qualifier:=qualifier, ref:=datasources())
'   Close the datasource connection
    retcode = SQLClose(connection)
   
End Sub

kyo_zy 发表于 2008-3-18 09:27:42

这个函数还是不能办到我需要的事情呀。。
就没有其它方法

村上舞!舞!舞 发表于 2008-3-18 10:52:12

如果只是从ORACLE中取出某表的数据可以用上面那个例子.通过ODBC连接的方式去取数据.然后再通过DDE通道来写入EXCEL文件中.完全可以实现啊...不知你是怎么弄得,办不到你需要的事情

kyo_zy 发表于 2008-3-18 13:29:44

帖下如何取数据保存到Excel中的代码
我用odbc是能取数据
Dim retcode As Variant
    Dim outputstr,query as string   
    connection = SQLOpen("DSN=ODBC_TMS421;UID=TMS421_LIJIA;PWD=THEIS", outputstr,)
    query = "select * from m_tkkncs"
    retcode = SQLExecQuery(connection,query)

   下面该怎么做
它可没有象Recordset一样的东西保存纪录,表数据怎么取然后有如何通过DDE通道写到Excel

村上舞!舞!舞 发表于 2008-3-24 08:47:41

不好意思,未能及时回答.给个从EXCEL单元格中读取数据的例子可以去参考一下,完全可以帮你完成你想要的工作
Function GetExcelData(sFileName As String, vSheet As String, sCell AsString) As String
    Dim objExcel As Object
    Dim objWorkBook As Object
    Dim objWorkSheet As Object
    Dim objRange As Object
   
    Set objExcel = CreateObject("Excel.Application")
    Set objWorkBook = objExcel.Workbooks.Open(FileName:=sFileName)
    Set objWorkSheet = objWorkBook.WorkSheets(vSheet)
   
    GetExcelData = objWorkSheet.Range(sCell).value
    objWorkBook.Close
    objExcel.Quit
    Set objWorkBook = Nothing
    Set objWorkSheet = Nothing
    Set objExcel = Nothing
End Function
页: [1]
查看完整版本: Rational Robot 对oracle数据库的测试