[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Alter Oracle Sequence in C#

Posted on 2013-05-22
2
Medium Priority
?
1,117 Views
Last Modified: 2013-05-22
I need to alter an Oracle Sequence in my code (C#) and I keep receiving an Invalid Cast error.  I've tried casting to INT64, INT32 and just INT and still get the same error.  Here is my code:

        public Boolean resetSEQ(OracleConnection connectionObj, String owner, String seqname)
        {
            Int64 currVal = 0;
            Boolean success = true;
            OracleCommand command = connectionObj.CreateCommand();
            try
            {
                // Reset Sequence
                ErrMsg = "";

                // Check that the database has been opened
                if (connectionObj == null || connectionObj.State != ConnectionState.Open)
                {
                    ErrMsg = "<br />Database is not opened.";
                    return false;
                }

                // Create Command object
                command.Connection = connectionObj;

                try
                {
                    // Get Current Sequence Value
                    command.CommandText =
                        "SELECT " + owner + "." + seqname + ".nextval FROM dual";

                    currVal = (int)command.ExecuteScalar();
                    ErrMsg = ErrMsg + currVal.ToString();
                }
                catch (Exception ex)
                {
                    ErrMsg = ErrMsg + "<br />Error Retrieving Next Sequence for " + seqname + ": " + ex.Message;
                    success = false;
                }
                //try
                //{
                //    // Get Current Sequence Value
                //    command.CommandText =
                //        "SELECT " + owner + "." + seqname + ".currval FROM dual";

                //    currVal = (Int64)command.ExecuteScalar();
                //    ErrMsg = ErrMsg + currVal.ToString();
                //}
                //catch (Exception ex)
                //{
                //    ErrMsg = ErrMsg + "<br />Error Retrieving Current Sequence for " + seqname + ": " + ex.Message;
                //    success = false;
                //}
            }
            catch (Exception ex)
            {
                ErrMsg = ErrMsg + "<br />ERROR resetSEQ: " + ex.Message;
                success = false;
            }
            finally
            {
                command.Dispose();
            }
            return success;
        }

Open in new window


The code only shows trying to get the current value of the sequence.  If I can get this working I can get the rest working.

Any help or suggestions would be greatly appreciated!
0
Comment
Question by:dyarosh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 39187163
Have you tried double or decimal? The numeric types coming back from Oracle, IMO, are not very intuitive. You might also try putting a breakpoint on the ExecuteScalar line and executing the following in the Immediate Window to check the type:

?command.ExecuteScalar().GetType()

Open in new window

0
 

Author Closing Comment

by:dyarosh
ID: 39187345
Casting as type Decimal worked.  Thanks.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

656 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