更改数据,ExecuteNonQuery()

using (mycon)
{
mycon.Open();

string MyTime;
DateTime dtDate;
MyTime = textBox1.Text.ToString();
string sql;
if (!DateTime.TryParse(MyTime, out dtDate))
{
MessageBox.Show("日期格式不正确!");
}
else
{
sql = "update [hf_zw].[dbo].[t_reservation] set reservation_service_time= '" + MyTime + "',state=1 where reservation_id=566";
SqlCommand mycom = new SqlCommand(sql, mycon);

//更改数据,ExecuteNonQuery()
mycom.ExecuteNonQuery();
MessageBox.Show("修改成功!");
}


}

}
else
{
MessageBox.Show("请勿快速操作!");
return;
}

}
catch
{

}
finally
{
mycon.Close();
// Console.WriteLine("成功关闭");
}

原文地址:https://www.cnblogs.com/asdyzh/p/9739222.html