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

x
?
Solved

DataAdapter fill causes "Operation is not valid due to the current state of the object" error

Posted on 2010-01-07
3
Medium Priority
?
1,798 Views
Last Modified: 2013-12-17
I've got a problem with the dataadapter.fill method
 
Everytime I run the code it reports "Operation is not valid due to the current state of the object."
 
Here is the code:
 
OracleConnection cnUnitEvent = new OracleConnection();
String cs = ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString;
OracleCommand cmdUnitEvent = new OracleCommand();
cnUnitEvent.ConnectionString = cs;
cnUnitEvent.Open();
String ct = "SELECT LK.PRELIMESTCOST, U.UNITNAME, LK.EVENTDETDESC ";
ct += "FROM ERFO.EVENTS_UNITSLINK LK JOIN ERFO.EVENTS E ON LK.EVENTID = E.EVENTID ";
ct += "JOIN ERFO.UNITS U ON LK.UNITID = U.UNITID WHERE LK.EventID = " + EventID.ToString();
cmdUnitEvent.CommandText = ct;
cmdUnitEvent.CommandType = CommandType.Text;
OracleDataAdapter daUnitEvents = new OracleDataAdapter();
DataSet ds = new DataSet();
//this.UnitEventDetails
DataTable dt = new DataTable();
daUnitEvents.SelectCommand = cmdUnitEvent;
daUnitEvents.Fill(dt);
ds.Tables.Add(dt);

 
I've also tried doing daUnitEvents.Fill(ds); and got the same error.  Mousing over the connection shows the connection state is open.  So I have no idea about the state of which object the error is referencing.
 
Help would be appreciated
0
Comment
Question by:Edward Joell
3 Comments
 
LVL 15

Assisted Solution

by:x77
x77 earned 500 total points
ID: 26203243
You need associate OracleCommand to OracleConnection.

    cmdUnitEvent.Connection = cnUnitEvent;

or

   cmdUnitEvent = cnUnitEvent.CreateCommand;
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 26203758
.NET data adapters can configure their own connections and commands.

Here is a simplified version to illustrate
string connectionString = ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString;
        string commandText = "SELECT LK.PRELIMESTCOST, U.UNITNAME, LK.EVENTDETDESC " +
                    "  FROM ERFO.EVENTS_UNITSLINK LK JOIN ERFO.EVENTS E ON LK.EVENTID = E.EVENTID " +
                    "  JOIN ERFO.UNITS U ON LK.UNITID = U.UNITID WHERE LK.EventID = " + EventID.ToString();
        using (OracleDataAdapter daUnitEvents = new OracleDataAdapter(commandText, connectionString))
        {
            DataTable dt = new DataTable();
            daUnitEvents.Fill(dt);
        }

Open in new window

0
 

Accepted Solution

by:
Edward Joell earned 0 total points
ID: 26204155
Right got the same answer from co-worker bout  half hour ago.  and it works.  thanks for responding.  will get back about points shortly
0

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
Suggested Courses
Course of the Month20 days, 10 hours left to enroll

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question