Click here to Skip to main content
15,903,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to update date in database where values are coming from datetimepicker
I am Using code
"dateTimePicker2.Value.Date"
But it is showing me error
"Cannot convert date or time from string"
Posted

Hi Ramesh,
Use dateTimePicker1.Value instead of dateTimePicker1.Text.

see here as usual same : http://social.msdn.microsoft.com/Forums/en/adodotnetdataproviders/thread/ff2f7106-9a5b-4b70-95c7-28e9ee14336a[^]
 
Share this answer
 
Without your code, it is difficult to be sure, but try using a parameterized query - you should use them anyway to avoid Sql Injection Attacks. If you are concatenating strings to form your sql UPDATE statement, it may be a localization thing. Since both Value and Value.Date return a DateTime value, you should be able to use them directly.
C#
using (SqlCommand com = new SqlCommand("UPDATE myTable SET myDateColumn=@DAT WHERE Id=@ID", con))
    {
    com.Parameters.AddWithValue("@ID", Id);
    com.Parameters.AddWithValue("@DAT", dateTimePicker2.Value.Date);
    com.ExecuteNonQuery();
    }
 
Share this answer
 
update table_name set date_colu_name='"+datetimepicker1.text+"' where date_colu_name is null
i am using access with c#.net,WHAT is the error in code? fast reply pls
 
Share this answer
 

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