Date and Time in Datagrid

tigz

Member
Joined
May 21, 2003
Messages
21
Hi,

im trying to display a report of information from an access 2000 database in a datagrid in my app. The problem is that it only shows the date and not the specific time, in a column used for showing the date and time a record was made in the database.

heres the code

Try
objConn.Open()
objDataAdapter.Fill(objDS, "REPORTS")

Catch ex As System.Exception
MsgBox(ex.Message)
Finally
If objConn.State = ConnectionState.Open Then
objConn.Close()
End If
End Try

objReportsTable.Rows.Clear()
objReportsTable = (objDS.Tables("REPORTS"))

lets the datagrid know that the dateandtime column holds both the data and the time
objReportsTable.Columns("DATEANDTIME").DataType = System.Type.GetType("System.DateTime")

Dim objFrmReport As New frmReport()

objFrmReport.datReport.DataSource = objReportsTable

objFrmReport.Show()

the try statement fills up the dataset with the data into a table called REPORTS, i then extract that table into a DataTable type variable, i then assign the datatable as the datasource of the datagrid and display.

I found another thread on here with the same problem and the suggestion was to declare the datatype of the column which is what ive implemented in the command on the 4th line from the bottom of the code.

Any ideas why this isnt working?
 
Hi,
The same problem you are having happened to me las week. The only way that I was able to display the date and time was to fix line 4 of your code:

Code:
objReportsTable.Columns("DATEANDTIME").DataType = System.Type.GetType("System.DateTime")

to

objReportsTable.Columns("DATEANDTIME").DataType = System.Type.GetType("System.String")

this has been the only solution that I have Found so far. I do not know how is going to work whenever you want to edit. but try it and see if it helps.

Best of Luck
 
Back
Top