[英]how to add data to timestamp column in sql server through c# coding in vb
我正在創建一個計費系統。 我在這里附上了銷售表格。 單擊保存按鈕時,需要將數據保存到賬單表中。 在帳單表中,帳單日期的數據類型為時間戳。
private void btnSave_Click(object sender, EventArgs e) {
string query = "INSERT INTO bill(bill_no,total_amount,bill_date) VALUES('"
+ txtBillNo.Text + "', '" + txtBillTotal.Text + "','" + txtBillDate.Text + "')";
using(con = new SqlConnection(connectionString)) {
SqlCommand com = new SqlCommand(query, con);
con.Open();
com.ExecuteNonQuery();
con.Close();
MessageBox.Show("Record added successfully!", "Save", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
SSMS列屬性的屏幕快照在sql的表中,您可以將bill_date列設置為
No
datetime
getdate()
成功插入表格后,這會自動將日期時間添加到字段中。
希望這可以幫助?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.