PC Review


Reply
Thread Tools Rate Thread

how to convert DateTime in short date and short time

 
 
Omer kamal
Guest
Posts: n/a
 
      12th Sep 2005
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
 
Reply With Quote
 
 
 
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      12th Sep 2005
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" <(E-Mail Removed)-kl.de> schreef in bericht
news:dg2u7n$5c3$(E-Mail Removed)-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



 
Reply With Quote
 
 
 
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      12th Sep 2005
Omer kamal <(E-Mail Removed)-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 - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
Paul Sullivan
Guest
Posts: n/a
 
      13th Sep 2005
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 <(E-Mail Removed)-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


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
short date, short time Mary Microsoft Access Queries 2 9th Jul 2009 02:06 PM
Short time vs short date RobUCSD via AccessMonster.com Microsoft Access Form Coding 1 8th Jun 2007 06:30 PM
System.DateTime doesn't convert to SqlDbType.DateTime Narshe Microsoft C# .NET 3 2nd Nov 2005 06:42 PM
DateTime problem: how to create datetime format hh:mm:ss AM/PM without the date mimi Microsoft C# .NET 1 6th Aug 2004 08:28 PM
Convert datetime to System.DateTime Martin Schmid Microsoft ADO .NET 1 24th Feb 2004 09:52 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:48 PM.