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

}

}

}

}

}

相关推荐
知识分享小能手1 小时前
Redis入门学习教程,从入门到精通,Redis 概述:知识点详解(1)
数据库·redis·学习
xixihaha13243 小时前
将Python Web应用部署到服务器(Docker + Nginx)
jvm·数据库·python
夕除3 小时前
Mysql--07
数据库·mysql
数据最前线3 小时前
5个瞬间,盘点国产数据库的2025年
数据库
jiankeljx3 小时前
Redis-配置文件
数据库·redis·oracle
xixihaha13243 小时前
Python游戏中的碰撞检测实现
jvm·数据库·python
Schengshuo3 小时前
SQL 中 COUNT 的用法详解
数据库·sql
顶点多余3 小时前
Mysql--后端与前端关系
数据库·mysql
mygljx3 小时前
【MySQL 的 ONLY_FULL_GROUP_BY 模式】
android·数据库·mysql
sunwenjian8864 小时前
Springboot项目本地连接并操作MySQL数据库
数据库·spring boot·mysql