I am new to ADO.net
I need to retrieve from DB a set of rows, then iterate one-be-one and send them, conditionally, to some objects which may UPDATE
or DELETE
received row from DB.
From SqlDataReader
documentation I didn't understand properly how it works (does it Read from DB all rows or only some of them or one-by-one?)
From MSDN:
Results are returned as the query executes, and are stored in the network buffer on the client until you request them using the Read method of the DataReader.
- When exactly result is returned? During
command.ExecuteReader()
or duringreader.Read()
? And what is the content of Result - all data or partial? - What is "network buffer" on local machine?
- From where
Read
reads data? From DB or from Cache?
Will affect data modifying (UPDATE
or DELETE
) retrieving from DB of next data?
Code stub:
using (SqlConnection connection = new SqlConnection(connectionString))
using (SqlCommand command = new SqlCommand(queryString, connection))
{
connection.Open();
using (SqlDataReader reader = command.ExecuteReader());
{
while (reader.Read())
{
//ReadSingleRow...
//Perform some checks and if TRUE send to a manager obeject whcih perform UPDATE or DELETE on this record
}
}
}
or better to use SqlDataAdapter
with DataSet
or DataTable
here?