I want to get one row record with SqlCommand. After data reader reading, I want to update LastLoginDate. But it fails. How can I update records in drf.Read() block.
SqlCommand kf = db.getCommand("SELECT Name FROM Members WHERE ID=1");
SqlDataReader drf = kf.ExecuteReader();
if (drf.Read())
{
txtName = drf["Name"].ToString();
using (SqlCommand kf2 = db.getCommand("UPDATE Members SET LastLogin=getdate() WHERE ID=@id"))
{
kf2.Parameters.AddWithValue("@id", 1);
int s = kf2.ExecuteNonQuery();
}
}