Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't Convert String to date in Datagrid??

Status
Not open for further replies.

meravsha

Programmer
Jul 27, 2001
21
0
0
IL
I don't understand why the colume doesn't change to date.
In my table there is a string Col like "20040505"
in the datagrid I want it to show "2004/05/05" or "05/05/2004"
I wrote:
Dim dgts As New DataGridTableStyle
.MappingName = dtt.TableName
For i = 0 To dtt.Columns.Count - 1
'DataGridColoredTextBoxColumn is similar to
'DataGridTextBoxColumn
ACol = New DataGridColoredTextBoxColumn

column_name = dtt.Columns(i).ColumnName
ACol.MappingName = column_name
ACol.HeaderText = column_name
If column_name = CODE Then
ACol.Width = 0
ElseIf column_name = "DateStr" Then
ACol.Format = "yyyy/MM/dd"
End If
dgts.GridColumnStyles.Add(ACol)
ACol = Nothing
Next
the code is working well except the format propery
please help!?
 
you cannot convert string value "20040505" into a date format "yyyy/MM/dd". change the format of date in your SELECT statement.

Email: pankajmsm@yahoo.com
 
Right, strings are strings. You'll want to use a CONVERT statement in your SQL to bring it back as a true DateTime value.

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top