Search code examples
sql-servervb.netexecutereader

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?


Solution

  • 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