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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:33:32+00:00 2026-05-28T05:33:32+00:00

I am running an insert query from c# using: string affectedRows = myCommand.ExecuteNonQuery().ToString(); However

  • 0

I am running an insert query from c# using:

string affectedRows = myCommand.ExecuteNonQuery().ToString();

However the query that I am running does two things. It first inserts stuff into a temp table, and then inserts stuff into the real-table.

Eg:

declare @t table (a int)
insert into @t 
values(1)

insert into MyTable
select * from @t

Since it does two inserts, my affectedrows will be 2.
The question is how to i get either the last result of the insert, or perhaps an array/list of results?

Dividing by 2 won’t help me, as there maybe multiple queries, etc and it won’t always be 2. the above is just an example. Thanks

  • 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-28T05:33:33+00:00Added an answer on May 28, 2026 at 5:33 am

    Just change the SET NOCOUNT statement to view the lines that really matter:

    example:

    set nocount off
    
    declare @t table (a int)
    insert into @t 
    values(1)
    
    set nocount on
    
    declare @MyTable table (b int)
    
    insert into @MyTable
    select * from @t
    

    See the Messages tab in SSMS.

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

Sidebar

Related Questions

After running a insert or update query against a SQLServer 2005 database, under what
I have a long running insert transaction that inserts data into several related tables.
So I'm trying to do a simple insert using Linq but i'm running into
I'm trying to insert text into a MySQL DataBase from a form using PHP.
Im running the following query from my PhpMyadmin sql tab CREATE TRIGGER testTrigger AFTER
I'm running two queries in my script room.php . Both are using MySQLi prepared
I have 30 tables of data that I'm running a query on, and then
When running a vim instance in gnu screen hitting shift enter in insert mode
I tried running the following statement: INSERT INTO VOUCHER (VOUCHER_NUMBER, BOOK_ID, DENOMINATION) SELECT (a.number,
I am running a cross server insert INSERT INTO server.database.dbo.table (Field) VALUES('test') Afterward, 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.