Click here to Skip to main content
16,012,468 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
Hello developers

I am importing one DataTable values to second DataTable by using and visualizing them in DataGridView.
C#
foreach (DataRow dr in datatable.Rows)
{
    datatable2.ImportRow(dr);
}

This code is working good but a problem is that my second DataTable contains a FIRST_DATE column whose values are like 02-06-09 12:09:25.
But, when I import first DataTable values into second DataTable values they are viewed like this 02.06.09 12:09 miliseconds are removed from all FIRST_DATA values.

Please solve my problem.

[Note: those removed are seconds, not milliseconds (spelled with double l, anyway)]
Posted
Updated 20-Dec-10 10:31am
v3
Comments
Richard MacCutchan 20-Dec-10 3:47am    
Just change the format on your display code such that it displays the time correctly. BTW it's the seconds that are missing.

1 solution

Hallo Vishu,

I can not verify loss of precision when importing rows. I did a quick test:

using System;
using System.Data;
namespace Removed_Seconds
{
    class Program
    {
        static void Main(string[] args)
        {
            DateTime datetime = DateTime.Now;
            DataTable tableOriginal = new DataTable("Original");
            tableOriginal.Columns.Add("Time", typeof(DateTime));
            DataTable tableCopy = new DataTable("Copy");
            tableCopy.Columns.Add("Time", typeof(DateTime));
            tableOriginal.Rows.Add(datetime);
            tableCopy.ImportRow(tableOriginal.Rows[0]);
            DateTime dtOriginal = (DateTime) tableOriginal.Rows[0]["Time"];
            DateTime dtCopy = (DateTime) tableCopy.Rows[0]["Time"];
            Console.WriteLine("Original Time: {0}:{1}", dtOriginal, dtOriginal.Millisecond);
            Console.WriteLine("Copy Time: {0}:{1}", dtCopy, dtCopy.Millisecond);
            Console.ReadKey();
        }
    }
}


Result: Values are imported as expected.
It seems you have some other problem.
Btw. You talked about Milliseconds but in your example you showed that Seconds are missing
(02.06.09 12:09)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900