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

}

}

}

}

}

相关推荐
初圣魔门首席弟子2 分钟前
Qt C++ 项目实战:修改共享头文件后的高效增量编译与快速发布流程
数据库
wb043072013 分钟前
仓库搬家不停业——从阿明的“在线换仓库“,看数据库迁移与 Schema 演进的实战方法论
数据库·adb·架构
lx188548698967 分钟前
Redis大Key阻塞:单线程CPU100%的致命陷阱
数据库·redis·缓存
IT策士10 分钟前
Redis 从入门到精通:位图、HyperLogLog、GEO
数据库·redis·缓存
IT策士24 分钟前
Redis 从入门到精通:Python 操作 Redis 进阶
数据库·redis·python
IvorySQL30 分钟前
PostgreSQL 技术日报 (6月8日)|索引预取迭代,AI 安全功能上新
数据库·人工智能·sql·安全·postgresql
阿正的梦工坊38 分钟前
【Rust】05-结构体、枚举与模式匹配
java·数据库·rust
cjp56040 分钟前
006.WEB_API使用本地数据库 SQLite + Dapper 入门教程
数据库·sqlite
新新学长搞科研42 分钟前
【广东省博促会主办】2026年第七届先进材料与智能制造国际学术会议(ICAMIM 2026)
大数据·前端·数据库·人工智能·物联网
睡不醒男孩0308231 小时前
CLup篇之PostgreSQL管理
数据库·postgresql