使用c#在acess db中加盖时间戳 [英] Time stamping in acess db using c#
本文介绍了使用c#在acess db中加盖时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
{OleDbConnection mycon = new OleDbConnection();
OleDbCommand command = new OleDbCommand();
command.CommandText = "INSERT INTO Table1 (Emp_ID, Asset_ID, Actual_Start) VALUES (?, ?, ?)";
command.Parameters.Add("@Emp_ID", OleDbType.VarChar, 80).Value = textBox1.Text;
command.Parameters.Add("@Asset_ID", OleDbType.VarChar, 80).Value = textBox2.Text;
command.Parameters.Add("@Actual_Start", OleDbType.Date).Value = DateTime.Now;
command.Connection = mycon;
mycon.Open();
command.ExecuteNonQuery();
}
这是我写的代码。我收到错误ConnectionString属性尚未初始化。
This is the code I have written. I got the error "ConnectionString property has not been initialized."
推荐答案
将您的代码更改为此
change your code to this
command.CommandText = "INSERT INTO Table1 (Emp_ID, Asset_ID, Actual_Start) VALUES (@Emp_ID, @Asset_ID, @Actual_Start)";
但你的错误是关于连接字符串。
检查这个
OLEDB连接字符串/ [ ^ ]
http://www.connectionstrings.com/access/ [ ^ ]
private void button1_Click(object sender,EventArgs e )
{OleDbConnection mycon = new OleDbConnection();
mycon.ConnectionString = @Provider = Microsoft.ACE.OLEDB.12.0; Data Source = C:\ Dinesh \C#\ GIS_Power \ WindstFormsApplication1 \ bin \ Power_DB1.accdb;
OleDbCommand command = new OleDbCommand();
command.CommandText =INSERT INTO Table1(Emp_ID,Asset_ID,Actual_Start)VALUES(?,?,?);
command.Parameters.Add(@ Emp_ID ,OleDbType.VarChar,80).Value = textBox1.Text;
command.Parameters.Add(@ Asset_ID,OleDbType.VarChar,80).Value = textBox2.Text;
command.Parameters.Add(@ Actual_Start,OleDbType.Date).Value = DateTime.Now;
mycon.Open();
command.Connection = mycon;
command.ExecuteNonQuery();
private void button1_Click(object sender, EventArgs e)
{OleDbConnection mycon = new OleDbConnection();
mycon.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Dinesh\C#\GIS_Power\WindowsFormsApplication1\bin\Power_DB1.accdb";
OleDbCommand command = new OleDbCommand();
command.CommandText = "INSERT INTO Table1 (Emp_ID, Asset_ID, Actual_Start) VALUES (?, ?, ?)";
command.Parameters.Add("@Emp_ID", OleDbType.VarChar, 80).Value = textBox1.Text;
command.Parameters.Add("@Asset_ID", OleDbType.VarChar, 80).Value = textBox2.Text;
command.Parameters.Add("@Actual_Start", OleDbType.Date).Value = DateTime.Now;
mycon.Open();
command.Connection = mycon;
command.ExecuteNonQuery();
这篇关于使用c#在acess db中加盖时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文