生如火花 发表于 2005-4-1 09:23:05

用ODBC连接的疑惑。。。。。

te是一个sql server的表
id   c1      c2
1      a       1
2      b       2
3      c       3
4      d       4
在msgbox里显示的是1,2,C,4。。。。。。。想取第2列。。。。也不会。。。。。。。。
'$Include "sqautil.sbh"
Sub Main
    Dim Result As Integer
    dim out1(1 to 4,1 to 1) as Variant
    dim out2(1 to 4,1 to 1) as Variant
    dim connection,i as long
    Dim retcode As Variant
    dim outputstr,query as string
    i=1
    while i<5
    connection = SQLOpen("DSN=te", outputstr,)
    query="select * from te"
    retcode = SQLExecQuery(connection,query)
    retcode = SQLRetrieve(connection,out1())
    msgboxout1(i,1)
'    sqaconsolewrite out1(1,i)
    retcode = SQLClose(connection)
   i=i+1
   wend
End sub

生如火花 发表于 2005-4-1 12:40:48

把query改成query="select c1 from te",只能取到第一行。其他行都没有取出来,msgbox没有任何内容

pcl2004_27 发表于 2005-4-1 22:10:23

楼主的代码有问题,修改代码如下:
'$Include "sqautil.sbh"
Sub Main
    Dim Result As Integer
    dim out1(1 to 3,1 to4) as Variant
   
    dim connection,i as long
    Dim retcode As Variant
    dim outputstr,query as string
    i=1
   
    connection = SQLOpen("DSN=te", outputstr,)
    query="select * from te"
    retcode = SQLExecQuery(connection,query)
    retcode = SQLRetrieve(connection,out1())
   while i<5
      msgboxout1(i,1)
      '      sqaconsolewrite out1(1,i)
      i=i+1
   wend
   retcode = SQLClose(connection)

End sub

生如火花 发表于 2005-4-2 14:33:53

Originally posted by pcl2004_27 at 2005-4-1 10:10 PM:
楼主的代码有问题,修改代码如下:
'$Include "sqautil.sbh"
Sub Main
    Dim Result As Integer
    dim out1(1 to 3,1 to4) as Variant
   
    dim connection,i as long
    Dim retcode ...
感谢pcl的指点,我修改代码如下,终于取到了第2列。
'$Include "sqautil.sbh"
Sub Main
    Dim Result As Integer
    dim out1(1 to 3,1 to 4) as Variant
   
    dim connection,i as long
    Dim retcode As Variant
    dim outputstr,query as string
    i=1
   
    connection = SQLOpen("DSN=te", outputstr,)
    query="select * from te"
    retcode = SQLExecQuery(connection,query)
    retcode = SQLRetrieve(connection,out1())
   while i<5
      msgboxout1(2,i)
      '      sqaconsolewrite out1(1,i)
      i=i+1
   wend
   retcode = SQLClose(connection)

End sub

erichhuang 发表于 2005-4-18 16:16:07

我只想把第1列的数据存入指定的文本中,添了一句代码,如下:

'$Include "sqautil.sbh"
Sub Main
    Dim Result As Integer
    dim out1(1 to 8,1 to 29) as Variant
   
    dim connection,i as long
    Dim retcode As Variant
    dim outputstr,query as string
    i=1
   
    connection = SQLOpen("DSN=LocalServer;UID=sa;PWD=88888", outputstr,)
    query="select * from qwe"
    retcode = SQLExecQuery(connection,query)
    retcode = SQLRetrieve(connection,out1())
    while i<30
      msgboxout1(1,i)
      'sqaconsolewrite out1(1,i)
      i=i+1
    wend
    retcode = SQLRetrieveToFile(connection,"c:\test.txt")
    retcode = SQLClose(connection)

End sub

但是文本中是存放的整个表的内容。。。。我得代码哪里错了呢?:$

niceleafage 发表于 2005-8-17 12:53:58

如何把数据库的密码写到脚本中?

描述:

    通过ODBC,robot已经与oracle连接好了,但是每次运行robot时,总是弹出 输入数据库密码的提示,输入完密码之后,才会运行下面的操作;

我的问题是:
   如何把数据库的密码直接写到脚本中,才不会运行robot时,弹出输入密码的提示框?
   知道的朋友,能否告知一下?多谢!:p

niceleafage 发表于 2005-8-17 12:56:48

呵呵,我已经解决了

呵呵,我已经解决了

gabriel 发表于 2005-8-19 15:22:14

解决了为什么不把你的成果和大家一起分享呢?

snowflake 发表于 2005-9-9 16:54:14

我完善了一下,只要在本地建立一个test数据库,然后建立一个TE表,修改一下连接登陆名字就OK了!

'$Include "sqautil.sbh"

Sub Main
    Dim Result As Integer
    dim out1(1 to 3,1 to 4) as Variant
   
    dim connection,i as long
    Dim retcode As Variant
    dim cnStr,outputstr,query as string
    i=1
    cnStr="driver={SQL Server};server=(local);uid=sa;pwd=;database=test"
    'cnStr="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=test;Data Source=(local);Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=TEST;Use Encryption for Data=False;Tag with column collation when possible=False"
    connection = SQLOpen(cnStr,outputstr,prompt:=4)
    query="select * from te"
    retcode = SQLExecQuery(connection,query)
    if retcode < 0 then
      msgbox "query error!"
    end if
   
    retcode = SQLRetrieve(connection,out1())
    if retcode < 0 then
      msgbox "retrieve error!"
    end if
   while i<5
      msgboxout1(2,i)
      '      sqaconsolewrite out1(1,i)
      i=i+1
   wend
   retcode = SQLClose(connection)
   
End sub

[ Last edited by snowflake on 2005-9-10 at 08:37 ]

sky2008 发表于 2006-9-14 10:55:31

顶顶顶

bjballoonfish 发表于 2007-4-23 14:26:14

有点看不懂了

wonew1228 发表于 2008-1-22 21:13:43

收益匪浅,学习……

yjr2008 发表于 2008-1-25 11:07:57

不太明白
页: [1]
查看完整版本: 用ODBC连接的疑惑。。。。。