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 6713439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:22:51+00:00 2026-05-26T08:22:51+00:00

bool ok = query.exec(CREATE TABLE person ( IdTable INTEGER IDENTITY(1,1) NOT NULL PRIMARY KEY,

  • 0
bool ok = query.exec("CREATE TABLE person ( IdTable INTEGER IDENTITY(1,1) NOT NULL PRIMARY KEY, LastName varchar(255), FirstName varchar(255)  )");            
bool ok1 = query.exec("INSERT INTO person VALUES ('Wijethilake','Tharanga')");            
QSqlQuery scope_Identity("SELECT SCOPE_IDENTITY() AS Current_Identity;");
QSqlRecord rec = scope_Identity.record();
qDebug() << scope_Identity.isValid();

This returns false. IS it that something wrong with qt or is my scope Identity statement wrong. I really appreciate someone’s help on this.

Thank you.

  • 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-26T08:22:52+00:00Added an answer on May 26, 2026 at 8:22 am

    This may be related to how QSqlQuery operates.

    I don’t know QSqlQuery, but I have had a similar issue with SCOPE_IDENTITY() in other languages where the INSERT and SELECT SCOPE_IDENTITY()... statements are run in different scopes – meaning that the results of the INSERT are not accessible to SCOPE_IDENTITY() – typically because they are executed as dynamic SQL by the data access layer. You can validate this by running a SQL trace on your database server for SQL:BatchCompleted events.

    Assuming this is the issue, you need to execute both statements in the same scope to return the new identity. I’m not sure if this is valid QSqlQuery, but something like

    QSqlQuery scope_Identity("INSERT INTO person VALUES ('Wijethilake','Tharanga'); SELECT SCOPE_IDENTITY() AS Current_Identity;");
    QSqlRecord rec = scope_Identity.record();
    qDebug() << scope_Identity.isValid();
    

    In SQL 2005 and later, an alternative to SCOPE_IDENTITY() is the OUTPUT clause, which enables you to do the whole thing in one statement:

    QSqlQuery scope_Identity("INSERT INTO person OUTPUT inserted.IdTable VALUES ('Wijethilake','Tharanga');");
    QSqlRecord rec = scope_Identity.record();
    qDebug() << scope_Identity.isValid();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

-(BOOL) textFieldShouldReturn:(UITextField*) theTextField{ [theTextField resignFirstResponder]; return YES; } it is not working....
Here is the update query which i am using to update a table. It
I would like to create a compiled query which uses reusable where predicates. An
I have a linq query that for whatever reason is not coming back ordered
I have this LINQ-query: bool? a, b, c; from i in _ctx.SomeEntitySet where (a
I have a Database class which contanins the follwing methods: public bool ExecuteUDIQuery(string query)
I have this: var sortName = Request.Params[sortName]; var query = Request.Params[query]; Func<UsuarioEndereco, bool> whereClause
please take a look at the following snippet: public IEnumerable<T> Query(Expression<Func<T, bool>> filter) {
I need to query a table using the bitwise operator to produce a dictionary
I'm trying to create a Linq query based on a user's input. Writing sql

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.