how to convert DateTime in short date and short time

  • Thread starter Thread starter Omer kamal
  • Start date Start date
O

Omer kamal

Dear all,

I want to save my data into MS Access database Table which consist of
some fields with short date and short time formats.
I try to save data in to the said table and I am getting error that my
SQL statment is not correct.

string strSQL = @"INSERT INTO Activities ( Task,Day,Start,Finish )
VALUES ( '"+id+"', '"+date+"', '"+start+"', '"+finish+"' )" ;

I think error is because i am not able to cast my variables correctly.

how can i convert my DateTime to short date and short Time formats???

regards,

Omer kamal
 
Omer kamal said:
I want to save my data into MS Access database Table which consist of
some fields with short date and short time formats.
I try to save data in to the said table and I am getting error that my
SQL statment is not correct.

string strSQL = @"INSERT INTO Activities ( Task,Day,Start,Finish )
VALUES ( '"+id+"', '"+date+"', '"+start+"', '"+finish+"' )" ;

I think error is because i am not able to cast my variables correctly.

how can i convert my DateTime to short date and short Time formats???

The trick is not to embed the values directly in the SQL in the first
place. Instead, use aparameterised command. See
http://www.pobox.com/~skeet/csharp/faq/#db.parameters
 
You should also be aware that date values are stored differnrtly in MS
Access, but the libray has methoids to convert both ways.

See:
DateTime.ToOADate Method
DateTime.FromOADate Method

Paul V. Sullivan
 
Back
Top