C# -- 使用ODBC连接数据库
时间:2021-07-01 10:21:17
帮助过:97人阅读
class ODBCHelper
{
public static string conString1 =
"Dsn=sqlServerDsn;DataBase=Test;Uid=User1;Pwd=123456;";
public static string conString2 =
"Dsn=oracleDsn;Uid=User1;Pwd=123456;";
public DataTable SQLServerExeQuery(
string sql)
{
using (OdbcConnection con =
new OdbcConnection(conString1))
{
using (OdbcCommand cmd =
new OdbcCommand(sql, con))
{
using (OdbcDataAdapter da =
new OdbcDataAdapter(cmd))
{
DataTable dt =
new DataTable();
con.Open();
da.Fill(dt);
return dt;
}
}
}
}
public DataTable OracleExeQuery(
string sql)
{
using (OdbcConnection con =
new OdbcConnection(conString2))
{
using (OdbcCommand cmd =
new OdbcCommand(sql, con))
{
using (OdbcDataAdapter da =
new OdbcDataAdapter(cmd))
{
DataTable dt =
new DataTable();
con.Open();
da.Fill(dt);
return dt;
}
}
}
}
}
ODBC DSN配置:
C# -- 使用ODBC连接数据库
标签:oracl public datatable and inf style 连接数据库 str exe