>我遇到问题 当我尝试通过按按钮设置用户到达的日期和时间时,系统数据中发生了类型为"系统.数据.OleDb.OleDbException"的未处理异常.dll --->条件表达式中的数据类型不匹配。
如何设置当前到达日期和时间,而不会收到此错误?
代码的一部分
bool clockedIn = false;
public void button1_Click(object sender, EventArgs e)
{
if (!clockedIn)
{
OleDbConnection myConnection = new OleDbConnection("\CONNECTION PATH");
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = myConnection;
cmd.CommandText = "Insert into Weekdays (Arrival)" + "values(@Arrival)";
cmd.Parameters.AddWithValue("@Arrival", DateTime.now);
myConnection.Open();
cmd.ExecuteNonQuery();
MessageBox.Show("Arrival added.");
myConnection.Close();
}
}
string query = "insert into table(data) values('"+DateTime.Now.ToString("yyyy-MM-dd")+"')";
OleDbConnection conexao = new OleDbConnection();
conexao.ConnectionString = this.string_conexao;
conexao.Open();
OleDbCommand comando = new OleDbCommand();
comando.CommandText = query;
comando.Connection = conexao;
try
{
comando.ExecuteNonQuery();
}
catch
{
}