Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to store the date in sql server using for c#.net.
please send the code
Posted

To store a date you can use date[^] data type. To set current date into the column in SQL Server use GETDATE()[^]

If you want to pass a date from client side, use SqlCommand[^] along with SqlParameter[^]
 
Share this answer
 
Comments
Shahin Khorshidnia 26-May-12 12:02pm    
+5
Wendelius 1-Jun-12 0:34am    
Thanks :)
Monjurul Habib 26-May-12 15:49pm    
5!
Wendelius 1-Jun-12 0:34am    
Thanks :)
 
Share this answer
 
v2
Comments
Shahin Khorshidnia 26-May-12 12:01pm    
Good Link +5
Mohammad A Rahman 26-May-12 20:29pm    
Thank you Shahin :)
Monjurul Habib 26-May-12 15:49pm    
5!
Mohammad A Rahman 26-May-12 20:29pm    
Thank you Monjurul :)
Hi,

if Your date Format is dd/MM/yyyy then u need to convert it in sql Format
using following Code

C#
IFormatProvider provider = new System.Globalization.CultureInfo("en-CA", true);
          string   strDate = DateTime.Parse(txtDate.Text.Trim(), provider, System.Globalization.DateTimeStyles.NoCurrentDateDefault).Date.ToString();


then u can pass it to Db ok

Best Luck
 
Share this answer
 
v2
do you want to insert the date values into database programmetically..?
C#
sqlconnection con=new Sqlconnection(Your Connection String);
sqlcommand cmd=new sqlcommand("Insert into db(Date) values(@Date)",con);
cmd.parameters.addwithvalue("@Date",Datetime.Now.ToString());//Present DateTime
cmd.parameters.addwithvalue("@Date",Datetime.Now.ToshortDateString);//It displays Only date value
cmd.ExecuteNonQuery();
Con.Close();
 
Share this answer
 
v2
Comments
koilkannan 5-Feb-13 1:09am    
i need store date value in sql database,i given the above code but it shown error ...
the name 'DateTime' does not exist in current context....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900