1.源代码
string connString = "User ID=scott;Password=yanhong;Data Source=(DESCRIPTION = (ADDRESS_LIST= (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = yanhong)))";
OracleConnection conn = new OracleConnection(connString);
try
{
conn.Open();
OracleCommand com=new OracleCommand("select * from emp ",conn);
DataSet ds=new DataSet();
OracleDataAdapter oda = new OracleDataAdapter(com);
oda.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
MessageBox.Show(conn.State.ToString());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
finally
{
conn.Close();
}
2.可能会出现“尝试加载 Oracle 客户端库时引发 BadImageFormatException。如果在安装 32 位 Oracle 客户端组件的情况下以 64 位模式运行,将出现此问题。“问题、
解决方法:
将项目属性的目标平台改成64位即可