我正在尝试使用以下代码更新数据库表中的LastUpdOn
列:
if (FileImgsave.HasFile == true)
{
string imgfile = Path.GetFileName(FileImgsave.PostedFile.FileName);
// FileImgsave.SaveAs("Images/" + imgfile);
FileImgsave.SaveAs(Server.MapPath("~/Images/" + imgfile));
sqlCon.Open();
SqlCommand cmd = sqlCon.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "UPDATE Advertisement SET Item = @item, ImgPath = @image, Name = @name WHERE AdvID = '" + AdsTb.Text + "'";
cmd.Parameters.AddWithValue("@name", nameTb.Text);
cmd.Parameters.AddWithValue("@item", imgfile);
cmd.Parameters.AddWithValue("@image", "~/Images/" + imgfile);
cmd.ExecuteNonQuery();
SqlCommand sqlCmd2 = new SqlCommand("UpdTime", sqlCon);
sqlCmd2.CommandType = CommandType.StoredProcedure;
sqlCmd2.ExecuteNonQuery();
// string qry = "UPDATE AdvertisementTest SET Item='" + itemTb.Text + "' WHERE AdvertisementID='"+AdsTb.Text+"' AND ImgPath='"+ImageTb.Text+"'";
sqlCon.Close();
FillGridView();
LitMsg.Text = "Update successfully!";
Clear();
ButSave.Enabled = true;
}
UpdTime查询在下面
ALTER PROC [dbo].[UpdTime]
AS BEGIN
UPDATE Advertisement
SET LastUpdOn = GETDATE()
END
我已经检查了数据库,并且LastUpdOn
列尚未更新,因此仍为NULL
。