Skip to Main Content

Database Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to use FillSchema() method in ADO.NET?

580752Jun 1 2007
How to use FillSchema() method in ADO.NET?
With referenced Oracle.DataAccess.Lite namespace;
I wrote the code as below:
using (conn = new OracleConnection(@"DSN=POLite; UID=System;PWD=manager"))
{
conn.Open();
OracleCommand cmd = new OracleCommand(conn);
cmd.CommandText = "select * from tbl_floor";

OracleDataAdapter adapter = new OracleDataAdapter(cmd);
DataTable dt = new DataTable();
adapter.FillSchema(dt, SchemaType.Source);
this.dataGridView1.DataSource = dt;
}
The InvalidCastException throws when execute adapter.FillSchema(dt, SchemaType.Source);
The message was: Unable to cast object of type 'Oracle.DataAccess.Lite.OracleCommand' to type 'System.Data.Common.DbCommand'.
I found OracleCommand was not inherited from DbCommand, but from IDbCommand.
So that, I have modified the code
using (conn = new OracleConnection(@"DSN=POLite; UID=System;PWD=manager"))
{
conn.Open();
OracleCommand cmd = new OracleCommand(conn);
cmd.CommandText = "select * from tbl_floor";
OracleDataAdapter adapter = new OracleDataAdapter(cmd);
DataSet ds = new DataSet();
adapter.FillSchema(ds, SchemaType.Source);
this.dataGridView1.DataSource = ds.Tables[0];
}
Unfortunately, the exception was thrown again.
Now, the message was: Unable to cast object of type 'System.String' to type 'System.Type'.
How to fill data schema to datable with oracle Lite?
Thanks in advance.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 29 2007
Added on Jun 1 2007
0 comments
1,610 views