期望目标:C#连接数据库,查询,返回其中一列的所有值,编译后,生成dll,供QTP调用
我使用的方法:1、返回string数组;2、返回dictionary;3、返回List<string>
由于C#与vbs识别的类型不一样,我感觉返回string数组应该是最靠谱的,但也没成功。
请各位大侠教教我该如何来处理?
题外话:为何这两天我在论坛按CTrl+Shift切换语言,常无响应,其他网页正常。是我的输入法问题?
C#代码如下,编译后生成dll
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;
namespace SqlTest
{
public class SelectTest
{
private Dictionary<int, string> dic;
public Dictionary<int,string> myData
{
get { return dic; }
}
public void GetData(string strCnn, string strCmd)
{
SqlConnection conn;
SqlCommand cmd;
dic = new Dictionary<int, string>();
conn = new SqlConnection(strCnn);
cmd = new SqlCommand(strCmd, conn);
conn.Open();
SqlDataReader dReader;
//returnData = new List<string>();
dReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
for(int i=0;dReader.Read()!=false;++i)
{
dic.Add(i, dReader[1].ToString());
}
}
}
}
QTP代码:
Dim testObj '调用.net的对象
Dim strCnn '数据库连接字符串
Dim strCmd '查询指令
Dim msgDic 'Dicitionary对象
strCnn ="Data Source=IP地址;Initial Catalog=数据库;User ID=用户名;password=密码"
Set test Obj=DotNetFactory.CreateInstance("SqlTest.SelectTest","H:\Test\ClassLibrary1\
ClassLibrary1\obj\Release\ClassLibrary1.dll")
strCmd = "select * from Address"
testObj.GetData strCnn,strCmd
'下面该如何调用myData返回数组?
msgDic = testObj.myData
msgbox msgDic.Items(0)
Set msgDic = Nothing
Set testObj = Nothing
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) | Powered by Discuz! X3.2 |