我已经开发了一个c#基本表单,当我点击提交时数据已经填入数据库,但我也想要那个时间&一旦用户点击表格,日期也会在数据库中填充,以便知道他何时提交此表格。
有人可以帮助。!!
以下是我到目前为止所做的任何事情的源代码。
namespace testing
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void label2_Click(object sender, EventArgs e)
{
}
private void label3_Click(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
}
private void submit_Click(object sender, EventArgs e)
{
OleDbConnection cnon = new OleDbConnection();
cnon.ConnectionString =@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\visual_c\Database71.accdb";
OleDbCommand command = new OleDbCommand();
command.CommandText = "INSERT INTO electricity (Asset_name,Asset_number,Emp_id) VALUES (@Asset_name, @Asset_number,@Emp_id)";
command.Parameters.AddWithValue("@Assetname", textBox1.Text);
command.Parameters.AddWithValue("@Assetnumber", textBox2.Text);
command.Parameters.AddWithValue("@emp_id", textBox3.Text);
cnon.Open();
command.Connection = cnon;
command.ExecuteNonQuery();
cnon.Close();
}
}
}
答案 0 :(得分:1)
为什么不
INSERT INTO electricity (Asset_name,Asset_number,Emp_id,timestamp)
VALUES (@Asset_name, @Asset_number,@Emp_id,now())
或更好,只需在表格中将timestamp字段的默认值设置为Now()即可,因此无需担心。
答案 1 :(得分:1)
最好是在电力中声明一个新字段并将其默认值设置为= now() 您无需修改代码。