String was not recognized as a valid DateTime

rosemacy

Member
Joined
Nov 13, 2015
Messages
8
Programming Experience
Beginner
Im using a datetime picker which supposed to be the current time will be displayed on my table column..

I used this to display on my datagrid..

dgvInfo.Rows(dgvInfo.RowCount - 1).Cells("colDateTime").Value = Convert.ToDateTime(dtRow("DateAndHour").ToString())

but I got the error message:String was not recognized as a valid DateTime
 
There is nothing in your code that relates at all to a DateTimePicker.

As for what the code does do, why are you converting a value from a DataRow into a String and then into a DateTime? Why isn't it a DateTime to start with? If it is then why are you converting it to a String?

As for the error, what is value of `dtRow("DateAndHour")` at the time? If that column can contain values that can't be converted to DateTimes then you need to test for that before converting them.
 
your right thankyou..I discarded the converting to String..just the DateTime..the error was gone thanks!just a little problem on displaying the DateTimePicker value on my datagridview column where the DateTime should be displayed..
 
Last edited:
Back
Top