[02/03] DataGrid Problem 12/30/1899
Hi all
I'm getting a date value back in the column that holds my timestamp, The value = 12/30/1899.
I'm loading data from a coma Delimited text file
FileData= 04/12/2007,15:00:00,MTempQ,61.765,degf,G
Heres the code.
Code:
Dim strConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=" & strFilePath & ";" _
& "Extended Properties=""text;HDR=NO;FMT=Delimited"""
Dim conn As New OleDb.OleDbConnection(strConnectionString)
conn.Open() ' Open connection with the database.
Dim objCmdSelect As New OleDb.OleDbCommand("SELECT * FROM [" & strFileName & "]", conn) ' Create new OleDbCommand to return data.
'Dim objCmdSelect As New OleDb.OleDbCommand("Select * from [Sheet1$]", conn) ' Create new OleDbCommand to return data from worksheet.
' Create new OleDbDataAdapter that is used to build a DataSet based on the preceding SQL SELECT statement.
Dim objAdapter1 As New OleDb.OleDbDataAdapter
objAdapter1.SelectCommand = objCmdSelect 'Pass the Select command to the adapter.
Dim objDataset1 As New DataSet 'Create new DataSet.
objAdapter1.Fill(objDataset1) 'Fill the DataSet with the information from the file.
formatview.DataGrid1.DataSource = objDataset1.Tables(0).DefaultView 'Build a table from the original data.
conn.Close() 'Clean up objects.
I'm Using vb.net 2003
Re: [02/03] DataGrid Problem 12/30/1899
Re: [02/03] DataGrid Problem 12/30/1899
Have you tried setting the data type for that column to string vs date to see what happens?
Re: [02/03] DataGrid Problem 12/30/1899
I just tried your code and I got exactly what I expected: 30/12/1899 3:00 PM. The DateTime data type ALWAYS has a date portion and a time portion. It's only reading a time from your data file so it's using the default date. If you want to ignore the date part then do so. If you don't want to display the date part to the user then don't. That's exactly what Access does, which you may or may not have seen. All Date/Time columns contain a full date and time value. The format of the column is just how the value is DISPLAYED. It doesn't affect how it's stored.
In all honesty, I have no idea how to format the contents of a column in a DataGrid because I've never done it. You would use the a format string that included only the time, e.g. "HH:mm:ss". As to where you put that format string, you should probably be able to find the answer here.
Re: [02/03] DataGrid Problem 12/30/1899
I have searched far and wide to get this answered and i cant seem to get much solved.
the only way i was able to get it to read the time was if i entered it into the DB as a string, but this is not practical for me because i need to set the default value of the field to "TIME()" so i can record the time dynamically.
i am using the access software to enter in the data. i just created a simple form for scanning barcodes.
it works well but like the other guy i keep getting 12/30/1899 as my time when i view it in .NET in my datagrid.
i tried changing the XML Schema to reflect that it was a time-specific box and not a date/time box, but no avail.
i would greatly appreciate it if anyone could give some insight on this problem because i fear i might have to wipe out my idea and create a .NET interface to enter the data into the tables, which will be very time consuming.
thank you!!
Justin