【发布时间】:2016-07-19 02:37:21
【问题描述】:
我正在尝试通过webform 在我的SQL 数据库中的表中插入一个新行。
问题是我需要将DateTime 值放在送货员分配完成时间的描述中。
但是因为该值是一个字符串,并且要求显示类似 "Received parcel by StationMgrSG on 19 July 2016 10:34am" 的内容,但我的代码显示类似“StationMgrSG on @TimeNow 收到的包裹”
如何更改值以显示日期和时间?
这是我的代码:
public int updateDeliveryHistory()
{
string strConn = ConfigurationManager.ConnectionStrings["NPCSConnectionString"].ToString();
SqlConnection conn = new SqlConnection(strConn);
SqlCommand cmad = new SqlCommand("INSERT INTO DELIVERYHISTORY(ParcelID, Description) VALUES (@ParcelId,'Received parcel by StationMgrSG on @TimeNow')",conn);
cmad.Parameters.AddWithValue("@ParcelId", parcelID);
cmad.Parameters.AddWithValue("@TimeNow", DHCreateTime);
conn.Open();
cmad.ExecuteNonQuery();
conn.Close();
return 0;
}
【问题讨论】:
标签: c# sql sql-server executenonquery