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

  • Home
  • SEARCH
  • 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 1108719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:07:40+00:00 2026-05-17T02:07:40+00:00

I am using the Informix.NET driver (C#) to insert a row into a database

  • 0

I am using the Informix.NET driver (C#) to insert a row into a database table. This works fine, except I have no idea how to get the ID of the last inserted row:

Insert Command:

    //Sample Query: "INSERT INTO names (id, name) values (0, 'John Smith');"
    public static void Insert(String query)
    {
        try
        {
            using (IFX::IfxConnection connection = ConnectionManager.GetConnection())
            {
                connection.Open();

                using (IFX::IfxCommand command = new IFX::IfxCommand(query, connection))
                    command.ExecuteNonQuery();

                if (connection != null) connection.Close();
            }
        }
        catch (IFX::IfxException)
        {
            throw;
        }
        catch (Exception)
        {
            throw;
        }
    }

If I change the query so that it includes: “SELECT DBINFO (‘sqlca.sqlerrd1’) FROM systables WHERE tabid = 1;” I get errors (this line works using unix dbaccess) I get errors.

I’ve also tried to change things such as using IFX::IfxReader reader = command.ExecuteReader() to try to get the results and read those results, however I get errors. (“ERROR [HY000] [Informix .NET provider][Informix]Cannot use a select or any of the database statements in a multi-query prepare.”). I’ve also tried to precede this with command.Prepare();, but that does nothing. I’m really not sure how to do an insert and get the ID through C# Informix.NET Client SDK.

=========
Oh, and I know I can run the two statements separately, which will work, except I’m worried that another insert will be executed in between the first and getting the ID number, which would result in errors.

  • 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-17T02:07:41+00:00Added an answer on May 17, 2026 at 2:07 am

    Granted I’ve never used this framework before, but I did needed like this in a different framework I worked with so what I ended up doing was doing a completely separate query to get the new element’s ID.

    My code was in PHP but in pseudocode it looked like:

    Insert(String query)
    {
       Execute the Sql Query: query
       result = Execute the Sql Query: "SELECT last_insert_id"
       return the first element of result
    }
    

    EDIT: I didn’t notice your edit, and that wasn’t an issue for me because it was PHP so it was single-threaded and so it was impossible for another statement to execute in the time between the two queries. However, if you add a lock to inserts you can force that both queries happen as a transaction. Also with a bit of RegEx you could probably construct a Select statement that uses the information in the Insert statement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have an application using the IBM Informix driver. Whenever we try to open
We have an Informix 4GL forms interface to our database, accessed using a terminal
Using Informix C++ interface, the first query is fine, but the second yields this
I have a problem connecting to Informix server(windows) using ADO.NET. I'm using Listing 1
I just started to work on informix.( I have been using mysql all my
INFORMIX-SE 7.32: I have a transaction table with about 5,000 nrows. The transaction.ticket_number[INT] is
I have to connect my app to a customer's Informix 7.2 legacy database. From
I have problem when I try insert some data to Informix TEXT column via
I have a small program that is trying to wrap an NHibernate insert into
I have Informix database with timestamp field defined as YEAR TO SECOND. When I

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.