Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7662661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:51:28+00:00 2026-05-31T13:51:28+00:00

From the Things that go bump in the database engine department: This function returns

  • 0

From the “Things that go bump in the database engine” department:

This function returns what looks like a valid value, but the record is not posted (no err msg):

private String GetInterpreterTicketIDSequenceVal()
{
    con = new OracleConnection(oradb);
    con.Open();

    String query = "SELECT TO_CHAR(SYSDATE,'YYYYMMDD-') || LTRIM(TO_CHAR(ABC.SOMETABLEID.NEXTVAL, '000000')) FROM DUAL";

    cmd = new OracleCommand(query, con);
    cmd.CommandType = CommandType.Text;
    //MessageBox.Show(cmd.ExecuteScalar().ToString());
    return cmd.ExecuteScalar().ToString();
}

…SEEMS to work (returns a value, and the insertion is (seemingly) made without squawking)… yet, no record is inserted into the database.

This kludgy (sp?) function, OTOH:

private String GetSomeTableIDSequenceVal_Fake()
{
    int iYear = DateTime.Now.Year;
    int iMonth = DateTime.Now.Month;
    int iDay = DateTime.Now.Day;
    int iHour = DateTime.Now.Hour;
    int iSecond = DateTime.Now.Second;

    String sYear = iYear.ToString();
    String sMonth = iMonth.ToString();
    String sDay = iDay.ToString();
    String sHour = iHour.ToString();
    String sSecond = iSecond.ToString();

    if (iMonth < 10)
    {
        sMonth = String.Format("0{0}", sMonth);
    }
    if (iDay < 10)
    {
        sDay = String.Format("0{0}", sDay);
    }
    if (iHour < 10)
    {
        sHour = String.Format("0{0}", sHour);
    }
    if (iSecond < 10)
    {
        sSecond = String.Format("0{0}", sSecond);
    }

    return String.Format("{0}{1}{2}-{3}{4}", sYear, sMonth, sDay, sHour, sSecond);
}

…works fine – the record is inserted into the database (the code that calls these functions follows).

It seems odd that they both return a string, yet one works, and one doesn’t… that column doesn’t have a constraint on it that is rejecting the value from the former function, so…???

Anyway, here’s the code that calls either of those functions, in context:

        try
        {
            con = new OracleConnection(oradb);
            con.Open();
            String query = "INSERT INTO ABC.SOMETABLE (TICKETID, TICKETSOURCE, ABOUTSOMEID, CATEGORYID, CONTACTEMAIL) VALUES (:p_TICKETID, :p_TICKETSOURCE, :p_ABOUTSOMEID, :p_CATEGORYID, :p_CONTACTEMAIL)";

            cmd = new OracleCommand(query, con);
            cmd.CommandType = CommandType.Text;

            // Params = TICKETID, TICKETSOURCE, ABOUTSOMEID, CATEGORYID, CONTACTEMAIL
            OracleParameter p_TICKETID = new OracleParameter();
            p_TICKETID.Direction = ParameterDirection.Input;
            p_TICKETID.OracleDbType = OracleDbType.NVarchar2;
            p_TICKETID.Size = 20;
            // This doesn't allow the record to be inserted...???
            //p_TICKETID.Value = GetSomeTableIDSequenceVal();
            // ...but when I "fake it" below, the record IS inserted
            //p_TICKETID.Value = GetSomeTableIDSequenceVal_Fake();                cmd.Parameters.Add(p_TICKETID);

            OracleParameter p_TICKETSOURCE = new OracleParameter();
            p_TICKETSOURCE.Direction = ParameterDirection.Input;
            p_TICKETSOURCE.OracleDbType = OracleDbType.NVarchar2;
            p_TICKETSOURCE.Size = 20;
            p_TICKETSOURCE.Value = textBoxTicketSource.Text;
            cmd.Parameters.Add(p_TICKETSOURCE);

            OracleParameter p_ABOUTSOMEID = new OracleParameter();
            p_ABOUTSOMEID.Direction = ParameterDirection.Input;
            p_ABOUTSOMEID.OracleDbType = OracleDbType.Int32;
            p_ABOUTSOMEID.Value = textBoxAboutSOMEID.Text;
            cmd.Parameters.Add(p_ABOUTSOMEID);

            OracleParameter p_CATEGORYID = new OracleParameter();
            p_CATEGORYID.Direction = ParameterDirection.Input;
            p_CATEGORYID.OracleDbType = OracleDbType.Int32;
            p_CATEGORYID.Value = textBoxCategoryID.Text;
            cmd.Parameters.Add(p_CATEGORYID);

            OracleParameter p_CONTACTEMAIL = new OracleParameter();
            p_CONTACTEMAIL.Direction = ParameterDirection.Input;
            p_CONTACTEMAIL.OracleDbType = OracleDbType.NVarchar2;
            p_CONTACTEMAIL.Size = 100;
            p_CONTACTEMAIL.Value = textBoxContactEmail.Text;
            cmd.Parameters.Add(p_CONTACTEMAIL);

            try
            {
                cmd.ExecuteNonQuery();
            }
            catch (OracleException ex)
            {
                MessageBox.Show(ex.Message);
            }
            MessageBox.Show("Apparent success");
        }
        finally
        {
            con.Close();
            con.Dispose();
        }

Update:

I added Xaction support, and it seems to make no difference whatsoever:

I encased it in a Transaction, and it makes no difference:

  OracleTransaction ot;
        . . .
        try
        {
            ot = con.BeginTransaction();
            cmd.Transaction = ot;
            cmd.ExecuteNonQuery();
            ot.Commit();
        }
        catch (Exception ex)
        {
            ot.Rollback();
        }

Update redux:

Luke made a good point about using two simultaneous connections; so, I changed that code to this:

private String GetInterpreterTicketIDSequenceVal()
{
    String query = "SELECT TO_CHAR(SYSDATE,'YYYYMMDD-') || LTRIM(TO_CHAR(ABC.SOMETABLEID.NEXTVAL, '000000')) FROM DUAL";

    OracleCommand oc = new OracleCommand(query, con);
    oc.CommandType = CommandType.Text;
    String s = oc.ExecuteScalar().ToString();
    try
    {
        return s;
    }
    catch (OracleException ex)
    {
        MessageBox.Show(ex.Message);
        return string.Empty;
    }
}

…but still no joy in Mudville.

Update redux revisited:

I got it working; thanks everybody for your help and insight.

Actually, it had been working for awhile – my stupid query in Toad was the problem – I forgot that I was adding a slightly different value in new records than what I was querying for … so it looked like the records weren’t being added, but they really were.
tgif!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:51:29+00:00Added an answer on May 31, 2026 at 1:51 pm

    I tried running your code above and I was only able to reproduce problems with it if the INTERPRETERTICKETID sequence had gone beyond 999999. If you are having problems then there must be something that you are not telling us. For example, how is your table INTERPRETERTICKET defined? What constraints are on it? How is the sequence defined? Are there any triggers on the table?

    Is there any need for your GetInterpreterTicketIDSequenceVal() method to use its own connection to the database? Can it not just use the same connection that the rest of your code does?

    If your sequence INTERPRETERTICKETID has gone beyond 999999 then the TO_CHAR call will return a string of hashes:

    SQL> select ltrim(to_char(999999, '000000')) from dual;
    
    LTRIM(T
    -------
    999999
    
    SQL> select ltrim(to_char(1000000, '000000')) from dual;
    
    LTRIM(T
    -------
    #######
    

    I put a PK constraint on the TICKETID column and after running your code twice, I got a constraint violation error.

    EDIT:

    In response to your comment, it is possible to use a trigger to populate the TICKETID column. You mentioned that your database apparently contains one such trigger, but without seeing how the trigger is defined, it’s difficult to know what the problem with it could be.

    I added the following trigger, and modified the C# code so that it didn’t attempt to insert a value for TICKETID. I ran the C# code a few times and it seemed to work.

    CREATE OR REPLACE TRIGGER INTERPRETERTICKETS_BI
      BEFORE INSERT ON INTERPRETERTICKETS
      FOR EACH ROW
    BEGIN
      SELECT TO_CHAR(SYSDATE,'YYYYMMDD-') || LTRIM(TO_CHAR(INTERPRETERTICKETID.NEXTVAL, '000000'))
        INTO :new.TICKETID
        FROM DUAL;
    END;
    /
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page of things that looks like this (and yes, I have
Checking few RDBMS I find that things like SELECT COUNT (a), SUM (b) FROM
What does it do? I read that it downloads things from Stdin, but where
I have this big function (1300+ lines of code) that takes data from the
I have a function that writes things from a binary tree. When I run
One of the many things that's been lacking from my scraper service that I
What are the things that Medium Trust stops you from doing? For example, I've
If you create a class library that uses things from other assemblies, is it
I've written a MIDlet that does several advanced things: fetching images from the web,
I've got quite a few SQL statements like such: SELECT foo FROM things WHERE

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.