How to use FillSchema() method in ADO.NET?
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.