我想用 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();
}
}