Why OLEDB for oracle does not work?
When Accessing Oracle Database using OleDb, I added a ";" in sql command,
string sqlCommandText="select * from tbllog;";
And I debugged it for 2 hours in the night. Later through analysis of programs written several days ago, I found that the sql statement with a ";" in the end would not work.
Thus I delete the ";", however, it still does not work using OleDb. I am confused.
The following is testing codes, the codes commented use the OleDb to access oracle database, and failed. The codes using OralceConnection of System.Data.OracleClient just do the work.
string connectionString=
System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
string sqlCommandText="select * from tbllog";
//here it is the failed solution using OleDB:
//should add "using System.Data.OleDb;" in the head
// string oleConnectionStr="Provider=OraOLEDB.Oracle;Data Source=OracleSID;User ID=UserID;Password=UserPass";
// OleDbConnection connection=new OleDbConnection();
// connection.ConnectionString=oleConnectionStr;
//
// OleDbCommand dbCommand=new OleDbCommand(sqlCommandText,connection);
// OleDbDataAdapter da=new OleDbDataAdapter();
// da.SelectCommand=new OleDbCommand(sqlCommandText,connection);
//Here's the successful solution using OracleClient:
//Should add reference of System.Data.OracleClient,
//and add "using System.Data.OracleClient;" in the head of .cs file
OracleConnection oOracleConn = new OracleConnection(connectionString);
OracleDataAdapter da=new OracleDataAdapter();
da.SelectCommand=new OracleCommand(sqlCommandText,oOracleConn);
//to fill data to DataSet from Data Adapter
DataSet ds=new DataSet();
da.Fill(ds,"tblLog");
//to display data in table "tblLog"
DataGrid1.DataSource=ds.Tables[0].DefaultView;
DataGrid1.DataBind();
Thus I delete the ";", however, it still does not work using OleDb. I am confused.
The following is testing codes, the codes commented use the OleDb to access oracle database, and failed. The codes using OralceConnection of System.Data.OracleClient just do the work.
posted on 2005-06-25 00:38 davidullua 阅读(429) 评论(0) 收藏 举报
浙公网安备 33010602011771号