CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    Join Date
    Oct 2007
    Posts
    40

    Add milliseconds to DataTable

    Hi .....

    How can i add milliseconds to datatable?

    i am adding like this.

    dataSet1.Tables["T_Log"].Columns.Add(new DataColumn(_customer.GetColumnName(colCount), typeof(System.DateTime)));

    regards
    laby

  2. #2
    Join Date
    Jan 2006
    Location
    18° 32' N / 73° 52' E
    Posts
    416

    Re: Add milliseconds to DataTable

    Is this what you are looking for ?

    Code:
    dataSet1.Tables["T_Log"].Columns.Add(new DataColumn(_customer.GetColumnName(colCount), typeof(System.DateTime.Now.Millisecond.ToString())));
    Regards,
    MMH
    Rate my post if you find it usefull.

  3. #3
    Join Date
    Oct 2007
    Posts
    40

    Re: Add milliseconds to DataTable

    hi
    thanks for the reply

    No.my data is "10:03:45.74 ".while adding to datatable millisecond is missing.how can i add milliseconds to datatable.

    regards
    laby

  4. #4
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Add milliseconds to DataTable

    You cant do it with a datetime field in the DB. You would have to use either a double or a string.

    Values with the datetime data type are stored internally by the SQL Server 2005 Database Engine as two 4-byte integers. The first 4 bytes store the number of days before or after the base date: January 1, 1900. The base date is the system reference date. The other 4 bytes store the time of day represented as the number of 1/300-second units after midnight.
    http://msdn2.microsoft.com/en-us/library/ms187819.aspx
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  5. #5
    Join Date
    Oct 2007
    Posts
    40

    Re: Add milliseconds to DataTable

    thanks

    so if i am using datatype as datetime,i am not able to add milliseconds to

    datatable .Is there any other solution for this

    regards
    laby

  6. #6
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Add milliseconds to DataTable

    I already gave you the two most common solutions...
    You would have to use either a double or a string.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  7. #7
    Join Date
    Oct 2007
    Posts
    40

    Re: Add milliseconds to DataTable

    now i am adding datatype as string to datatable for time field.but in my application vr providing Search based on time.how can i search for time,when i use (<,>,<=,>=)
    regards
    laby

  8. #8
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Add milliseconds to DataTable

    Quote Originally Posted by laby
    now i am adding datatype as string to datatable for time field.but in my application vr providing Search based on time.how can i search for time,when i use (<,>,<=,>=)
    regards
    laby
    If that is what you want to do, then you would be better using a numberical type. Store the data using a integer with enough bits to hold the number of milliseconds since some starting time. If you are using SQLServer2005 or later, you could also create a new type using C#.....
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  9. #9
    Join Date
    Oct 2007
    Posts
    40

    Re: Add milliseconds to DataTable

    thanks for the reply

    But i am reading Data from a log file to datatable.For searching i am using dataview.RowFilter method

    regards
    laby

  10. #10
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    1,080

    Re: Add milliseconds to DataTable

    You're asking the wrong question. If you're saving a DateTime value to a database then it already "contains" milliseconds, as every DateTime value does. If you aren't seeing the milliseconds then that's because you aren't displaying the value properly, not because it doesn't contain the right data. Try this:
    Code:
    DateTime now = DateTime.Now;
    
    MessageBox.Show(now.ToShortDateString());
    MessageBox.Show(now.ToShortTimeString());
    MessageBox.Show(now.ToLongTimeString());
    MessageBox.Show(now.ToString());
    MessageBox.Show(now.ToString("d/MM/yyyy h:mm:ss tt"));
    MessageBox.Show(now.ToString("d/MM/yyyy HH:mm:ss.fff"));
    MessageBox.Show(now.ToString("d/MM/yyyy HH:mm:ss.fffffff"));
    So you see, all the information is there and, if you want to see it, you simply have to show it properly.
    Tutorials: Home & Learn | Start VB.NET | Learn VB.NET | C# Station | GotDotNet | Games in VB.NET 101 Samples: 2002 | 2003 | 2005 | More .NET 2.0 (VB.NET, C#) Articles: VB.NET | C# | ASP.NET | MoreFree Components: WFC | XPCC | ElementsEx | VBPP | Mentalis | ADO.NET/MySQL | VisualStyles | Charting (NPlot, ZedGraph) | iTextSharp (PDF) | SDF (CF) ● Free Literature: VB 2005 (eBook) | VB6 to VB.NET (eBook) | MSDN Magazine (CHM format) ● Bookmarks: MSDN | WinForms .NET | ASP.NET | WinForms FAQ | WebForms FAQ | GotDotNet | Code Project | DevBuzz (CF) ● Code Converter: C#/VB.NET | VB.NET/C# | VS 2005 add-in

  11. #11
    Join Date
    Oct 2007
    Posts
    40

    Re: Add milliseconds to DataTable

    The actual data is (10:07:32.76).i tried the way u told but the value from datatable contains only
    10:07:32

    thanks & regards

    laby

  12. #12
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    1,080

    Re: Add milliseconds to DataTable

    If your original data contains partial seconds and the data in the Datatable doesn't then you're obviously reading the data incorrectly. As you are yet to show us how you are reading the data it simply isn't possible for us to determine what you're doing wrong.
    Tutorials: Home & Learn | Start VB.NET | Learn VB.NET | C# Station | GotDotNet | Games in VB.NET 101 Samples: 2002 | 2003 | 2005 | More .NET 2.0 (VB.NET, C#) Articles: VB.NET | C# | ASP.NET | MoreFree Components: WFC | XPCC | ElementsEx | VBPP | Mentalis | ADO.NET/MySQL | VisualStyles | Charting (NPlot, ZedGraph) | iTextSharp (PDF) | SDF (CF) ● Free Literature: VB 2005 (eBook) | VB6 to VB.NET (eBook) | MSDN Magazine (CHM format) ● Bookmarks: MSDN | WinForms .NET | ASP.NET | WinForms FAQ | WebForms FAQ | GotDotNet | Code Project | DevBuzz (CF) ● Code Converter: C#/VB.NET | VB.NET/C# | VS 2005 add-in

  13. #13
    Join Date
    Oct 2007
    Posts
    40

    Re: Add milliseconds to DataTable

    i am adding like this.

    dataSet1.Tables["T_Log"].Columns.Add(new DataColumn(_customer.GetColumnName(colCount), typeof(System.DateTime)));

    regards
    laby

  14. #14
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    1,080

    Re: Add milliseconds to DataTable

    Quote Originally Posted by laby
    i am adding like this.

    dataSet1.Tables["T_Log"].Columns.Add(new DataColumn(_customer.GetColumnName(colCount), typeof(System.DateTime)));

    regards
    laby
    That's adding the DataColumn to the DataTable. We don't care about that. We want to know how you're reading the data and adding it to a DataRow that is then added to the DataTable.
    Tutorials: Home & Learn | Start VB.NET | Learn VB.NET | C# Station | GotDotNet | Games in VB.NET 101 Samples: 2002 | 2003 | 2005 | More .NET 2.0 (VB.NET, C#) Articles: VB.NET | C# | ASP.NET | MoreFree Components: WFC | XPCC | ElementsEx | VBPP | Mentalis | ADO.NET/MySQL | VisualStyles | Charting (NPlot, ZedGraph) | iTextSharp (PDF) | SDF (CF) ● Free Literature: VB 2005 (eBook) | VB6 to VB.NET (eBook) | MSDN Magazine (CHM format) ● Bookmarks: MSDN | WinForms .NET | ASP.NET | WinForms FAQ | WebForms FAQ | GotDotNet | Code Project | DevBuzz (CF) ● Code Converter: C#/VB.NET | VB.NET/C# | VS 2005 add-in

  15. #15
    Join Date
    Oct 2007
    Posts
    40

    Re: Add milliseconds to DataTable

    I am adding data from logfile to DATATABLE.The code is given below

    dataSet1.Tables["T_Log"].Rows.Add(colData);

    then dispalying using datagridview

    dataGridView.Datasource=T_Log;.but here milliseconds is missing

    regards
    laby

Page 1 of 2 12 LastLast

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

Featured