[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 771
  • Last Modified:

Oracle .NET error System.Data.Common.DbCommand'. System.Data at System.Data.Common.DbDataAdapter

Simply try to update with dataadapter, what is wrong
-------------------------------------------------------------------------------------------------------------------------------
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Oracle.DataAccess.Client;
...
using (OracleConnection conn = new OracleConnection(Dal.DefaultConnectionString)) {                
   conn.Open();
   OracleDataAdapter da = new OracleDataAdapter("SELECT STATUS, RETURN_XML FROM aaa WHERE sequence_no = '" +   sequence_no.ToString() + "'", conn);

   OracleCommandBuilder cb = new OracleCommandBuilder(da);
   DataTable dt = new DataTable();                
   da.FillSchema(dt, SchemaType.Mapped);
   dt.Rows[0]["STATUS"] = "T";
   da.Update(dt);                
}
-------------------------------------------------------------------------------------------------------------------------------
Unable to cast object of type 'Oracle.DataAccess.Client.OracleCommand' to type 'System.Data.Common.DbCommand'. System.Data at System.Data.Common.DbDataAdapter.get_SelectCommand() at System.Data.Common.DbDataAdapter.FillSchema(DataTable dataTable, SchemaType schemaType) at Service_JFP.Page_Load(Object sender, EventArgs e) in e:\sites\edvs\Service\JFP.aspx.cs:line 58
0
karanba
Asked:
karanba
1 Solution
 
gjutrasCommented:
Instead of
OracleDataAdapter da = new OracleDataAdapter("SELECT STATUS, RETURN_XML FROM aaa WHERE sequence_no = '" +   sequence_no.ToString() + "'", conn);

   OracleCommandBuilder cb = new OracleCommandBuilder(da);
   DataTable dt = new DataTable();                
   da.FillSchema(dt, SchemaType.Mapped);
try
OracleCommand cmd = new OracleCommand(SELECT STATUS, RETURN_XML FROM aaa WHERE sequence_no = '" +   sequence_no.ToString() + "'", conn);
OracleDataAdapter da = new OracleDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
DataTable dt = ds.Tables[0];
0
 
Dux11Commented:
The function where the code is failing is expecting the parameter to be a type of System.Data.Common.DbCommand but you are sending it an object in the type of Oracle.DataAccess.Client.OracleCommand.

It would be useful to know where it is failing, it says line 58 but I am not sure which line 58 is as this isnt the complete code.  But it does appear to come down to using incorrect/unexpected object types.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now