0

Sorry if this is a silly question, how can we insert a row in postgresql database and read the same row again in one call?

ExecuteReader doesn't insert rows in database, ExecuteScalar and ExecuteNonQuery will return only one allow.

Is there a command to read entire row after inserting?

1 Answer 1

1

You query has to have the two commands, end each command with a semi-colon

String query = @"INSERT INTO table (a,b) VALUES (1,'x');
SELECT * FROM table WHERE (a = 1);";

Use ExecuteReader(query) It will work fine.

Who said ExecuteReader can't be used for inserts ?

All 3 Execute- methods can execute whatever commands to the database however, ExecuteReader will read the returned rows, ExecuteNonQuery will not return any result, ExecuteScalar only returns the value from the first column of the first row of your query.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi Siraj, Thanks for the answer I am passing Stored Proc in Execute Reader and its not inserting anything..
It was mistake from my side, Apologies :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.