Oracle Access 数据库连接 使用

直接代码吧:

 

/// <summary>
/// Oracle数据库连接
/// </summary>
/// <param name="path">数据库连接串,例如:(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = IP)(PORT = *)))(CONNECT_DATA =(SERVICE_NAME = *)))</param>
/// <param name="user">用户名</param>
/// <param name="psw">用户密码</param>
/// <returns>Oracle数据库连接对象</returns>
private static OracleConnection ConnectOracle(string path, string user, string psw)
{
OracleConnection oracleConn = new OracleConnection();
string connectionStr = string.Format("Data Source={0};User Id={1};Password={2};", path, user, psw);
oracleConn.ConnectionString = connectionStr;
return oracleConn;
}
/// <summary>
/// Access数据库连接
/// </summary>
/// <param name="path">数据库连接串,例如:@"D:\qingdan.accdb;"</param>
/// <param name="flag">Access版本,true为高于2007版</param>
/// <returns>Access数据库连接对象</returns>
private static OleDbConnection ConnectOracle(string path,bool flag)
{
OleDbConnection accessConn = null;
if (string.IsNullOrWhiteSpace(path) || !File.Exists(path))
{
MessageBox.Show("Acess数据库文件不存在", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return accessConn;
}
string conStr = null;
if (flag)
{
conStr = "Provider=Microsoft.Ace.OleDb.12.0;";
conStr += "Data Source=" + path;
conStr += ";Persist Security Info=False;";
}
else
{
conStr = "Provider=Microsoft.Jet.OLEDB.4.0;";
conStr += "Data Source=" + path;
}
accessConn = new OleDbConnection(conStr);
return accessConn;
}
    

以上是建立数据库连接的方法。

 

 

对Oracle数据库的查询操作方法如下:

 

string sqlTest = "";//此处为查询SQL
m_dsSet = new DataSet();//查询结果集合
OracleDataAdapter command = new OracleDataAdapter(sqlTest, m_oracleConn);
command.Fill(m_dsSet, "ds");

 

对Access数据库操作:

 

OleDbCommand dbCommand = new OleDbCommand();
dbCommand.Connection = m_accessConn;//连接串
dbCommand.Transaction = m_accessConn.BeginTransaction();
dbCommand.CommandText ="";//操作命令SQL
dbCommand.ExecuteNonQuery();
dbCommand.Transaction.Commit();

 

本文出自 “一条(……)路” 博客,请务必保留此出处http://hansong007.blog.51cto.com/5646787/1368898

Oracle Access 数据库连接 使用,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。