using
MySQLDriverCS; 
//
建立数据库连接
MySQLConnection DBConn;
DBConn
=
new
MySQLConnection(
new
MySQLConnectionString(
"
localhost
"
,
"
mysql
"
,
"
root
"
,
""
,
3306
).AsString);
DBConn.Open(); 
//
执行查询语句
MySQLCommand DBComm;
DBComm
=
new
MySQLCommand(
"
select Host,User from user
"
,DBConn); 
//
读取数据
MySQLDataReader DBReader
=
DBComm.ExecuteReaderEx(); 
//
显示数据
try
{
while
(DBReader.Read())
{
Console.WriteLine(
"
Host = {0} and User = {1}
"
, DBReader.GetString(
0
),DBReader.GetString(
1
));
}
}
finally
{
DBReader.Close();
DBConn.Close();
}

//
关闭数据库连接
DBConn.Close();--------------------------------------------------------------------------------
5.C#连接IBM DB2
程序代码:
--------------------------------------------------------------------------------
OleDbConnection1.Open();
//
打开数据库连接
OleDbDataAdapter1.Fill(dataSet1,
"
Address
"
);
//
将得来的数据填入dataSet
DataGrid1.DataBind();
//
绑定数据
OleDbConnection1.Close();
//
关闭连接 
//
增加数据库数据
在Web Form上新增对应字段数量个数的TextBox,及一个button,为该按键增加Click响应事件代码如下:
this
.OleDbInsertCommand1.CommandText
=
"
INSERTsintosADDRESS(NAME,
EMAIL, AGE, ADDRESS) VALUES
(
'
"+TextBox1.Text+"
'
,
'
"+TextBox2.Text+"
'
,
'
"+TextBox3.Text+"
'
,
'
"+TextBox4.Text+"
'
)
"
;
OleDbInsertCommand1.Connection.Open();
//
打开连接
OleDbInsertCommand1.ExecuteNonQuery();
//
执行该SQL语句
OleDbInsertCommand1.Connection.Close();
//
关闭连接 --------------------------------------------------------------------------------
6.C#连接SyBase
程序代码: (OleDb)
--------------------------------------------------------------------------------
Provider=Sybase.ASEOLEDBProvider.2;Initial Catalog=数据库名;User ID=用户名;Data Source=数据源;Extended Properties="";Server Name=ip地址;Network Protocol=Winsock;Server Port Address=5000;