【发布时间】:2014-01-23 09:02:41
【问题描述】:
我已经开发了一个 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();
}
}
}
【问题讨论】: