开发者

DataTables in c#

开发者 https://www.devze.com 2023-01-07 11:05 出处:网络
I am importing an excel sheet to a DataTable in a window application using oledb and want to fetch only the date which is the first column in my excel sheet. I have entered only dates in this column.

I am importing an excel sheet to a DataTable in a window application using oledb and want to fetch only the date which is the first column in my excel sheet. I have entered only dates in this column. but DataTable is adding time to it which I don't want. How to get only开发者_StackOverflow中文版 date in the table?


There is no Date data type in .NET. All date values come out as DateTime. You can get the date with a "0" time value using datevalue.Date.


Quoting Thorsten:

There is no Date data type in .NET. All date values come out as DateTime. You can get the date with a "0" time value using datevalue.Date.

Also be careful: if you inserted dates with "0 time" and you're getting back dates with non-zero time maybe you're running into one of those Excel date-format issues (thus your date should be quite different from the one you've input).


Use Linq on DataTable

 string[] array = gdt01T01S060
              .AsEnumerable()
              .Select(row => row.Field<string>("RequestedPartNo"))
              .ToArray();


for (int i = 0; i < array.Length; i++)
        {
            array[i] = Convert.ToDateTime(array[i]).ToString("mm/dd/yyyy");
        }

check out the date format. according to you.

0

精彩评论

暂无评论...
验证码 换一张
取 消