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

}

}

}

}

}

相关推荐
tcoding5 分钟前
《MySQL 技术内幕-innoDB 存储引擎》笔记
数据库·笔记·mysql
Edward.W26 分钟前
如何有效防止 SQL 注入攻击?
数据库·sql
好想有猫猫1 小时前
【Redis】服务端高并发分布式结构演进之路
数据库·c++·redis·分布式·缓存
桥Dopey2 小时前
关系型数据库PostgreSQL for Mac 保姆级使用教程
数据库·postgresql
@_猿来如此2 小时前
Django 实现电影推荐系统:从搭建到功能完善(附源码)
数据库·后端·python·django
nbsaas-boot2 小时前
SQL Server 存储过程开发手册
数据库
uncofish2 小时前
springboot不连接数据库启动(原先连接了mysql数据库)
数据库·spring boot·mysql
Databend3 小时前
大数据是不是凉了?
数据库
学也不会3 小时前
雪花算法
java·数据库·oracle
瀚高PG实验室4 小时前
数据库未正常关闭后,再次启动时只有主进程,数据库日志无输出
数据库