DataReader Object in ADO.NET do not updates the data because it is stream-based forward-only and it can be created only by calling executed reader method not by directly from code. Data Reader in ADO is mostly used while performing select operations in the application.
Data Reader contains one row at a time so it needs to fill again and again while retrieving records.
It is used with the SQLCommand class by the ExecuteReader method.

The DataReader object provides a connection oriented access or you can say connected approach to the data source and connection object can contain only one data reader at a time. So when we want to read data we should open the data reader and it will always points to the first record.
The read() method in the data reader is used to read records and forward-only if record exists.
SqlDataReader reader = null;
using (SqlConnection sqlConnection = new SqlConnection(ConnectionString))
{
List<SqlParameter> parameterList = new List<SqlParameter>();
parameterList.Add(new SqlParameter("@Email", emp.Email));
parameterList.Add(new SqlParameter("@Password", emp.Password));
parameterList.Add(new SqlParameter("@DeviceUUID", emp.DeviceUUID));
parameterList.Add(new SqlParameter("@DeviceType", emp.DeviceType));
if (sqlConnection.State == ConnectionState.Closed)
{
sqlConnection.Open();
}
reader = SqlHelper.ExecuteReader(sqlConnection, CommandType.StoredProcedure, "uspAuthenticateUser", parameterList.ToArray());
if (reader.HasRows)
{
while (reader.Read())
{
empResponse.accessToken = reader["AccessToken"] != null ? Convert.ToString(reader["AccessToken"]) : String.Empty;
fullName = reader["FullName"] != null ? Convert.ToString(reader["FullName"]) : String.Empty;
empResponse.Status = true;
empResponse.Message = "User successfully logged in.";
break;
}
0 Comment(s)