Results 1 to 5 of 5

Thread: [02/03] DataGrid Problem 12/30/1899

  1. #1

    Thread Starter
    Lively Member Brian Henry's Avatar
    Join Date
    Oct 2005
    Posts
    94

    [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
    Last edited by Brian Henry; May 22nd, 2007 at 08:21 PM.

  2. #2

    Thread Starter
    Lively Member Brian Henry's Avatar
    Join Date
    Oct 2005
    Posts
    94

    Re: [02/03] DataGrid Problem 12/30/1899

    Any one.

  3. #3
    Fanatic Member Jumpercables's Avatar
    Join Date
    Jul 2005
    Location
    Colorado
    Posts
    592

    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?

    C# - .NET 1.1 / .NET 2.0

    "Take everything I say with a grain of salt, sometimes I'm right, sometimes I'm wrong but in the end we've both learned something."
    _____________________
    Regular Expressions Library
    Connection String
    API Functions
    Database FAQ & Tutorial

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    New Member
    Join Date
    Jul 2007
    Posts
    6

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width