我想在我的web服務中獲取系統日期和時間。但我不確定如何去做。如何在webservice中獲取系統日期時間
這是我的代碼:
public void InsertStudentTransaction(string Name, string CLass, string NRIC, string StallNo, string AmountSpent, DateTime Date)
{
using (SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["nConnectionString2"].ConnectionString))
{
int StallNo1 = int.Parse(StallNo);
float AmountSpent1 = float.Parse(AmountSpent);
Date = DateTime.Now;
SqlCommand command = new SqlCommand("INSERT Into StudentTransactions (Name, CLass,NRIC,StallNo,AmountSpent, TimeDate) VALUES (@Name, @CLass, @NRIC, @StallNo, @AmountSpent, @Date)", conn);
command.Parameters.AddWithValue("@Name", Name);
command.Parameters.AddWithValue("@CLass", CLass);
command.Parameters.AddWithValue("@NRIC", NRIC);
command.Parameters.AddWithValue("@StallNo",StallNo1);
command.Parameters.AddWithValue("@AmountSpent", AmountSpent1);
command.Parameters.AddWithValue("@TimeDate", Date);
conn.Open();
command.ExecuteNonQuery();
}
}
你已經擁有它'DateTime.Now'究竟是什麼問題? –
您是否嘗試過調試您的代碼? – Sabilv
是啊我已經試過我想從我的web服務讀取系統日期時間並插入到我的數據庫中。 –