C# -- 使用ODBC连接数据库
C# -- 使用ODBC连接数据库
public 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配置: