可做产品预售的网站,电商一键上货软件,app软件开发价目表,网站制做通过GBASE南大通用 ADO.NET 接口读取GBASE南大通用Server 数据需要下面的步骤#xff1a;
1) 使用 GBASE南大通用Connection 创建数据库连接对象
2) 使用 GBASE南大通用Command 创建命令对象
3) 使用连接对象打开连接
4) 设置命令对象的 CommandText 属性#xff0c;指明…通过GBASE南大通用 ADO.NET 接口读取GBASE南大通用Server 数据需要下面的步骤
1) 使用 GBASE南大通用Connection 创建数据库连接对象
2) 使用 GBASE南大通用Command 创建命令对象
3) 使用连接对象打开连接
4) 设置命令对象的 CommandText 属性指明查询语句并关联连接对象
5) 执行命令对象的 ExecuteReader 方法后返回结果集
ExecuteReader方法指定 CommandBehavior.SingleResult参数时返回
单个结果集。
ExecuteReader 方法指定 CommandBehavior.Default 参数时返回多个
结果集。
6) 关闭数据连接
下面的例子将展示如何循环读取某一列的所有数据并打印出来。
C# 示例
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Data;
using GBase.Data.GBaseClient;
namespace UsingAdoNet
{
class Program
{
static void Main(string[] args)
{
String _ConnStr server192.168.5.41;user
idroot;password1;databasetest;poolingfalse;
using (GBaseConnection _Conn new
GBaseConnection(_ConnStr))
{
try
{
_ String _CmdText select * from
test.test;
GBaseCommand cmd new GBaseCommand(_CmdText,
_Conn);
_Conn.Open();
GBaseDataReader reader
cmd.ExecuteReader(CommandBehavior.SingleResult);
while (reader.Read())
{
Console.WriteLine(reader.GetValue(0));
}
reader.Close();
}
catch (GBaseException ex)
{
Console.WriteLine(ex.StackTrace);
}
finally
{
if( _Conn ! null )
_Conn.Close();
}
}
}
}
}