ExecuteReader and ExecuteNonQuery
ExecuteReader : ExecuteReader used for getting the query results as a DataReader object. It is readonly forward only retrieval of records and it uses select command to read through the table from the first to the last.
SqlDataReader reader;
reader = Command.ExecuteReader();
while (reader.Read()) {
MessageBox.Show(reader.Item(0));
}
reader.Close();
ExecuteNonQuery : ExecuteNonQuery used for executing queries that does not return any data. It is used to execute the sql statements like update, insert, delete etc. ExecuteNonQuery executes the command and returns the number of rows affected.
int retValue = 0;
Command = new SqlCommand(Sql, Connection);
retValue = Command.ExecuteNonQuery();
Related Topics
- C# ADO.NET Command
- C# ADO.NET SqlCommand - ExecuteNonQuery
- C# ADO.NET OleDbCommand - ExecuteNonQuery
- C# ADO.NET SqlCommand - ExecuteScalar
- C# ADO.NET OleDbCommand - ExecuteScalar
- C# ADO.NET SqlCommand - ExecuteReader
- C# ADO.NET OleDbCommand - ExecuteReader
- C# ADO.NET DataReader
- C# ADO.NET SqlDataReader
- C# ADO.NET OleDbDataReader
- C# Multiple Result Sets
- C# Table Schema from SqlDataReader
- C# Table Schema from OleDbDataReader
- C# ADO.NET DataAdapter
- C# ADO.NET SqlDataAdapter
- C# ADO.NET OleDbDataAdapter
- System.Data.SqlClient.SqlException: Login failed for user
Related Links