我正在尝试在我的网络服务中获取系统日期和时间。但我不确定该怎么做。
这是我的代码:
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();
}
}