Link to home
Create AccountLog in
Avatar of Billy Ma
Billy MaFlag for Hong Kong

asked on

C# Invalid Operation Exception

I do not know how to close the Data Reader....
because I need to run 2 different queries, the program stopped at the second query....
anyone can help?
error.jpg
ASKER CERTIFIED SOLUTION
Avatar of Arabia_vn
Arabia_vn
Flag of Viet Nam image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Billy Ma

ASKER

do you mean I should close the connection?

I am connecting my Oracle database using Olb.
SOLUTION
Avatar of Todd Gerbert
Todd Gerbert
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
so difficult...I am new to C#....
I have got no experience and no knowledge...I just did it by trial and error
sigh...i create one more command object......
seem stupid...but easier.
OleDbConnection connection = new OleDbConnection(connectionString);

                connection.Open();

                string query = "UPDATE WORK_RATING R " + 
                               "SET R.YEAR = '" + newYear.Text + "', " + 
                               "R.PLANNED_RATING = '" + newPlannedRating.Text + "', " +
                               "R.ACTUAL_RATING = '" + newActualRating.Text + "' " + 
                               "WHERE R.WORK_ID = '" + selectedWorkID + "' " +
                               "AND R.YEAR = '" + oldYear + "'";

                //Response.Write(query);
                OleDbCommand command = new OleDbCommand();
                command.CommandType = CommandType.Text;
                command.CommandText = query;
                command.Connection = connection;

                GridView2.DataSource = command.ExecuteReader();

                query = "UPDATE WORK_OPTION O " +
                        "SET O.YEAR = '" + newYear.Text + "', " +
                        "O.PLANNED_OPTION = '" + newPlannedOption.Text + "', " +
                        "O.ACTUAL_OPTION = '" + newActualOption.Text + "' " +
                        "WHERE O.WORK_ID = '" + selectedWorkID + "' " +
                        "AND O.YEAR = '" + oldYear + "'";

                //Response.Write(query);
                command = new OleDbCommand();
                command.CommandType = CommandType.Text;
                command.CommandText = query;
                command.Connection = connection;

                GridView2.DataSource = command.ExecuteReader();

                connection.Close();

                GridView2.EditIndex = -1;
                LoadData2();
                message2.Visible = false;

Open in new window

SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
I just wanna run the update statement
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
thanks