crimson589
crimson589

Reputation: 1306

ExecuteReader for executing Insert/Update query

Ok so I was just given this old vb.net(2008) program to make some changes to and I found something weird. The Insert/Update queries are being executed with ExecuteReader, it goes something like this

Dim sqlcommand as new SqlCommand("Insert query", connection)
Dim sqldatareader as SqlDataReader = sqlcommand.ExecuteReader()

And for some reason it works, it inserts/updates the data properly. Is there any draw backs to this? should I bother going through the program and change everything to ExecuteNonQuery?

Upvotes: 0

Views: 2841

Answers (2)

Be Kind To New Users
Be Kind To New Users

Reputation: 10063

Look carefully at the INSERT command, if it has an OUTPUT clause then it can actually return data.

Upvotes: 2

Jayasurya Satheesh
Jayasurya Satheesh

Reputation: 8033

Execute Reader is normally used when you expect your SQL Command to return some output. Such as Select a row. But if you don't have any results, but just a plain Insert or Update, then ExecuteNonQuery is sufficient

Upvotes: 1

Related Questions