Re: Insert Date
From: Miha Markic [MVP C#] (miha)
Date: 03/19/04
- Next message: Miha Markic [MVP C#]: "Re: SqlConnection.ConnectionString"
- Previous message: Miha Markic [MVP C#]: "Re: Manipulate DataSets"
- In reply to: Chris: "Insert Date"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 19 Mar 2004 09:32:11 +0100
Hi,
To be on the safe side, you should use parametrised sql insert command.
Something like:
SqlCommand cmd = new SqlCommand("INSERT INTO Table (..., datecolumn) VALUES
(@mydate)", ...)
cmd.Parameters.Add ("@mydate", SqlDbType.DateTime);
You should convert your date to DateTime type:
DateTime mydate = new DateTime(Int32.Parse(datestring.Substring(4, 4)),
Int32.Parse(datestring.Substring(2, 2)), Int32.Parse(datestring.Substring(0,
2)));
And prior to executing the command you should set the data:
cmd.Parameters["@mydate"].Value = mydate; // DateTime instance
Note, that I didn't test the code (typos possible :) )
-- Miha Markic [MVP C#] - RightHand .NET consulting & software development miha at rthand com www.rthand.com "Chris" <anonymous@discussions.microsoft.com> wrote in message news:7D1EB38E-0AC9-405C-96EB-BB8B59548867@microsoft.com... > Hi, > I have a column with data type datetime. How do I insert this 03042004?
- Next message: Miha Markic [MVP C#]: "Re: SqlConnection.ConnectionString"
- Previous message: Miha Markic [MVP C#]: "Re: Manipulate DataSets"
- In reply to: Chris: "Insert Date"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|