我正試圖通過webform
將一行插入到SQL
數據庫中的一個表中。C#中ExecuteNonQuery的SQL語句
問題是我需要將DateTime
的值放在Deliveryman分配完成時的描述中。
但是因爲該值是一個字符串,要求是顯示這樣的事情"Received parcel by StationMgrSG on 19 July 2016 10:34am"
但我的代碼是「由StationMgrSG上@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;
}
如果您在此數據的數據庫中有DateTime列,效果會更好。 –