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

}

}

}

}

}

相关推荐
杰克尼44 分钟前
MYSQL-175. 组合两个表
数据库·mysql
DemonAvenger1 小时前
MySQL索引原理深度解析与优化策略实战
数据库·mysql·性能优化
189228048611 小时前
NY270NY273美光固态闪存NY277NY287
服务器·网络·数据库·科技·性能优化
星霜笔记5 小时前
Docker 部署 MariaDB+phpMyAdmin+Nextcloud 完整教程
运维·数据库·docker·容器·mariadb
wyiyiyi10 小时前
【Web后端】Django、flask及其场景——以构建系统原型为例
前端·数据库·后端·python·django·flask
天宇_任11 小时前
Mysql数据库迁移到GaussDB注意事项
数据库·mysql·gaussdb
xiep143833351014 小时前
Ubuntu 安装带证书的 etcd 集群
数据库·etcd
Java小白程序员14 小时前
Spring Framework:Java 开发的基石与 Spring 生态的起点
java·数据库·spring
老虎062715 小时前
数据库基础—SQL语句总结及在开发时
数据库·sql·oracle
爱掘金的土拨鼠17 小时前
国产化dm数据库锁表解锁
数据库