472,121 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,121 software developers and data experts.

how to convert DateTime in short date and short time

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
Nov 17 '05 #1
3 15708
Omar,

Use parameters (the rest should go automatic)

http://msdn.microsoft.com/library/de...eterstopic.asp

Be aware that you have in OleDb to add the parameters in the sequents of
occurence of your SQL string

I hope this helps,

Cor

"Omer kamal" <om**@rhrk.uni-kl.de> schreef in bericht
news:dg**********@news.uni-kl.de...
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

Nov 17 '05 #2
Omer kamal <om**@rhrk.uni-kl.de> wrote:
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

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #3
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
On Mon, 12 Sep 2005 05:55:35 +0200, Omer kamal <om**@rhrk.uni-kl.de>
wrote:
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


Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Sorisio, Chris | last post: by
5 posts views Thread by simon | last post: by
17 posts views Thread by Terry Jolly | last post: by
2 posts views Thread by aqmaiya | last post: by
2 posts views Thread by kirke | last post: by
4 posts views Thread by =?Utf-8?B?YW5kcmV3?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.