0

我遇到问题System.Data.dll 中发生了“System.Data.OleDb.OleDbException”类型的未处理异常--->当我尝试通过按下设置用户到达的日期和时间时,标准表达式中的数据类型不匹配按钮。

如何设置当前的到达日期和时间,而不会出现此错误?

部分代码

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();
        }

}

4

1 回答 1

0
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
{
}
于 2014-01-14T19:27:16.050 回答