Shan Dush
Shan Dush

Reputation: 1

Access Database Doesn't update properly

I have been creating a software in C#. I tried to update some information in my Access database. Here's my database fields.Date ,total_h, W_hours, delay_h. Date is the Primary key. So I want to Update data where Date="datetimePicker.text". here is the Code What I tried.

try
{
    connection.Open();
    OleDbCommand cmd = new OleDbCommand();
    cmd.Connection = connection;               
    string update = "update summery_data set total_h='"+tHour+"', delay_h='"+delay+"' WHERE Date= " + dateTimePicker1.Text + " ";      
                    cmd.CommandText = update;
                    cmd.ExecuteNonQuery();
                    MessageBox.Show(" Updated successfully");
                    connection.Close();
}
catch(Exception ex)
{
    MessageBox.Show(ex.Message);
}

The Program is running properly without any Exception and displaying the "Updated successfully" message also. But when I open and Check the database the data has not been updated. I can't Understand what the problem is...?. please help me someone knows about it.

Upvotes: 0

Views: 88

Answers (1)

Jack
Jack

Reputation: 67

change

string update = ".... WHERE Date= " + dateTimePicker1.Text + " ";

to

string update = ".... WHERE Date= DateValue ('" + dateTimePicker1.Text + "') ";

Upvotes: 1

Related Questions