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

}

}

}

}

}

相关推荐
做cv的小昊7 分钟前
【TJU】信息检索与分析课程笔记和练习(6)英文数据库检索—web of science
大数据·数据库·笔记·学习·全文检索
严同学正在努力41 分钟前
VMware安装银河麒麟V10操作系统X86_64全过程
数据库·鸿蒙系统·kylin
智源研究院官方账号1 小时前
众智FlagOS 1.6发布,以统一架构推动AI硬件、软件技术生态创新发展
数据库·人工智能·算法·架构·编辑器·硬件工程·开源软件
dishugj1 小时前
[SQLSERVER] Lock Waits/sec参数含义详解
数据库·oracle·sqlserver
我科绝伦(Huanhuan Zhou)1 小时前
Oracle锁等待深度解析:从理论到实战的全方位指南
数据库·oracle
小Mie不吃饭1 小时前
Oracle vs MySQL 全面对比分析
数据库·mysql·oracle
我科绝伦(Huanhuan Zhou)1 小时前
KingbaseES数据库备份与恢复深度解析:原理、策略与实践
数据库·金仓数据库
烤鱼骑不快1 小时前
ubuntu系统安装以及设置
linux·数据库·ubuntu
BORN(^-^)1 小时前
达梦数据库索引删除操作小记
数据库·达梦
!chen2 小时前
Oracle 高风险锁等待快速诊断手册
数据库·oracle