我想用SqlCommand获取一行记录。读完数据后,我想更新LastLoginDate。但它失败了。如何更新drf.Read()块中的记录。
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();
}
}