简体   繁体   中英

how to set DateTime.now as current time in Access DataBase - c# windows forms app

Im having problems with An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll ---> data type mismatch in criteria expression when i try to set the date and time of user's arrival by pressing on button.

How can i set the current date and time of arrival, without getting this error?

A part of the code

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
{
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM