GBASE南大通用数据库通过 GBase ADO.NET 接口读取数据

通过 GBase ADO.NET 接口读取 GBase Server 数据需要下面的步骤:

  1. 使用 GBaseConnection 创建数据库连接对象

  2. 使用 GBaseCommand 创建命令对象

  3. 使用连接对象打开连接

  4. 设置命令对象的 CommandText 属性,指明查询语句,并关联连接对象

  5. 执行命令对象的 ExecuteReader 方法后返回结果集

 ExecuteReader方法指定 CommandBehavior.SingleResult参数时返回 单个结果集。

 ExecuteReader 方法指定 CommandBehavior.Default 参数时返回多个 结果集。

  1. 关闭数据连接

下面的例子将展示如何循环读取某一列的所有数据,并打印出来。

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 = "server=192.168.5.41;user id=root;password=1;database=test;pooling=false";

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();

}

}

}

}

}

相关推荐
ss2734 小时前
为什么PostgreSQL适合AI场景?
数据库·人工智能·postgresql
瑞克-桑切斯4 小时前
7、MySQL 慢查询排查与优化实战指南
java·服务器·数据库
z06.5 小时前
MySQL索引
数据库·mysql
考虑考虑5 小时前
Posrgresql恢复.backup文件
数据库·后端·postgresql
云祺vinchin5 小时前
中小企业备份软件选型从恢复需求到总体成本评估
数据库·数据备份·中小企业备份·容灾备份软件
Zenova EdgeOS5 小时前
Go 工业边缘错误处理实战:用 errors 构建可追溯错误链
开发语言·数据库·golang
KKKlucifer5 小时前
国内数据安全服务的产品智能化转型:大模型赋能下的技术能力重构分析
大数据·数据库·重构
字节跳动开源6 小时前
OpenViking 上线原生 3D 内容理解模型
数据库·开源
CCIE-Yasuo9 小时前
网络安全-学习数据库-Mysql-2
数据库·学习·mysql
这个DBA有点耶9 小时前
内核级AI与多模融合:AI数据库在海外场景的落地要点
数据库·人工智能·架构