Reputation: 1306
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
Reputation: 10063
Look carefully at the INSERT
command, if it has an OUTPUT clause then it can actually return data.
Upvotes: 2
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