convert string value into date format

osl

Member
Joined
Jun 8, 2006
Messages
20
Programming Experience
5-10
Hi,

I am got this datetime value into datagrid cell with {0:dd/MM/yyyy} as data formatting expression. Displayed at datagrid's fine ie. 14/07/2006 but after I edited it to 14/07/2007 and try to save, it will prompt this msg.
Cast from string "14/07/2006" to type 'Date' is not valid.

I've tried to update with this format #14/7/2006# too but still failed.

Below are my codes, pls help to see where when wrong.
Thanks!




Dim vCdate As String, tb As TextBox
Dim key As String = DataGrid1.DataKeys(e.Item.ItemIndex).ToString()
tb =
CType(e.Item.Cells(2).Controls(0), TextBox)
vCdate = tb.Text

Dim r As DSComplaint.tblComplaintRow
r = DsComplaintEdit1.tblComplaint.FindByComplaintNo(key)
r.CompDate = vCdate

SqlDataAdapter1.Update(DsComplaintEdit1)
DataGrid1.EditItemIndex = -1
DataGrid1.DataBind()
 
dim j as date = now 'gives you the current date

'inside a method
'month has to be uppercase or you will receive a range from 0-59
Format(j, "dd/MM/yyyy")
 
Hmm.. There is a warning that appears to tell you that just because a date can be formatted into a string, it might not be formattable back again.

I would actually recommend that you create a column specially for your date types, that show dates in a textbox, all formatted etc, but when they are edited, the editor component is a date time picker

the following article discussed this:
http://msdn.microsoft.com/msdnmag/issues/05/04/CuttingEdge/
 
Back
Top