代表一个打开的GBase 服务器数据库连接。这个类不能被继承。对于该类
所有成员的列表,参考 GBaseConnection 成员。
继承层次
System.Object
|__ System.MarshalByRefObject
|__ System.ComponentModel.Component
|__ System.ComponentModel.Component
|__ GBase.Data.GBaseClient.GBaseConnection
语法
[ Visual Basic ]
GBase 8a 程序员手册ADO.NET 篇
- 156 -
南大通用数据技术股份有限公司
Public NotInheritable Class GBaseConnection _
Inherits DbConnection _
Implements ICloneable
[ C# ]
public sealed class GBaseConnection : DbConnection, Icloneable
必要条件
命名空间:GBase.Data.GBaseClient
线程安全性
这个类型的公共静态成员(在Visual Basic 中为 Shared)对于多线程操
作是保证线程安全的,对于实例不保证线程安全性。
注释
一个GBaseConnection 对象代表一个GBase 数据源的连接。当用户创建一
个GBaseConnection 实例的时候,所有属性被设置为初始值。对于这些值的列
表,参考GBaseConnection 构造函数。
如果GBaseConnection 完成功能后,用户调用Close 关闭连接。
示例
下面的例子创建了一个GBaseCommand 和一个 GBaseConnection。
GBaseConnection 打开并设置为GBaseCommand 的Connection,然后调用了
ExecuteNonQuery,并关闭连接。
[Visual Basic]
Public Sub InsertRow(gsConnectionString As String)
' If the connection string is null, use a default.
If gsConnectionString = "" Then
gsConnectionString ="Database=Test;DataSource=localhost;
"_
&"UserId=username;Password=pass;pooling=false"
End If
GBase 8a 程序员手册ADO.NET 篇
南大通用数据技术股份有限公司
- 157 -
Dim gsConnection As New GBaseConnection(gsConnectionString)
Dim
gsInsertQuery
As
String
=
"INSERT
INTO
Orders
(id,
customerId,
"_ &"amount) Values(1001, 23, 30.66)"
Dim gsCommand As New GBaseCommand(gsInsertQuery)
gsCommand.Connection = gsConnection
gsConnection.Open()
gsCommand.ExecuteNonQuery()
gsCommand.Connection.Close()
End Sub
[C#]
public void InsertRow(string gsConnectionString)
{
// If the connection string is null, use a default.
if(gsConnectionString == "")
{
gsConnectionString
=
"Database=Test;Data
Source=localhost;
User Id=username;Password=pass;pooling=false";
}
GBaseConnection gsConnection = new GbaseConnection
(gsConnectionString);
string gsInsertQuery = "INSERT INTO Orders (id, customerId,
amount) Values(1001, 23, 30.66)";
GBaseCommand gsCommand = new GBaseCommand(gsInsertQuery);
gsCommand.Connection = gsConnection;
gsConnection.Open();
gsCommand.ExecuteNonQuery();
gsCommand.Connection.Close();
}