I used datetimepicker.value.date to insert the value in database.

Then I used this

dateTimePicker1.Value= Convert.ToDateTime(dt.Rows[0]["Issued_Date"]);

But it doesn't work, neither .ToString().

What data type is the Issued_Date column in your database?

datetime. but i used datetimepicker to only get the date using .date

But it doesn't work, neither .ToString().

How does it not work?
If you get errors then please post these.
If the result is not what you expect, then explain how the result is in error.

Try examining the value of the returned object.
Break the line in to two parts like this.

object tempObj = dt.Rows[0]["Issued_Date"];
dateTimePicker1.Value= Convert.ToDateTime(tempObj);

Now set a break point on the second line and examine the value of tempObj.
Is it what you expected?


  1. What is the date/time format of the picker producing? (ie: what is the order of the date/time value)
  2. What error are you getting when you say it "doesn't work"

In theory the date/time generated by the picker should match an accepted date/time format in use by SQL server, however, if it doesn't then you would receive an error from SQL Server indicating an invalid date/time format. If this is the case then you need to change the format output of the picker to match an accepted format for date/time before submitting the result to the database.

Hope this helps :) Please remember to mark the thread solved once your issue is resolved.

Edit: removed portion of my reply that was a result of not enough caffeine and having just woken up :twisted:

Hmm....i posted a long message with sample code and its not here : / grr.
Essentially i said what nick said about checking the returned data to ensure its in the format you expect.
I ran a test app and it worked fine converting the Value.Date to and from the database and updated the datetimepicker so the problem seems to be elsewhere.

private void button3_Click(object sender, EventArgs e)
            using (DataSet1TableAdapters.testTableAdapter adpt = new fill_picturebox.DataSet1TableAdapters.testTableAdapter())

        private void button4_Click(object sender, EventArgs e)
            DataTable dt = new DataTable();
            using (DataSet1TableAdapters.testTableAdapter adpt = new fill_picturebox.DataSet1TableAdapters.testTableAdapter())
                dt = adpt.GetData();
            dateTimePicker1.Value = (DateTime)dt.Rows[0]["testDate"];

            //also tested and worked with
            dateTimePicker1.Value = Convert.ToDateTime(dt.Rows[0]["testDate"]);

@Lusiphur: Ahh You edited your post!!!:confused:

commented: Too quick for my click! :P +1

You're too quick for me nick :P

I had just finished editing out that portion of my reply and as the page reloaded here was your reply about it :twisted:

Ah well, note to self, don't skim the forums here until the first half of the Red Bull has kicked in!

When I tried same, what you've suggested, i am getting a new issue. Although the code is compiling without any error, but shows a different date !!! the field contains date as "13-12-2003" but the control shows "13-05-2010" !!!

What should I do???

What should I do???

What you should do is post a new thread with your own question.

Include samples of your code (specifically the parts involved in the generation and manipulation of your dateTime component) and details of what you're trying to do with the code so that people can take a look and try to help you :)

Resurrecting a 15+ day old thread with something that is not *directly* related to the original post is usually not going to result in answers for you :twisted:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.