如何将Excel上传到数据表? [英] How Do I Upload Excel Into Datatable?

查看:80
本文介绍了如何将Excel上传到数据表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我在excel表中有一些数据只包含时间。但是当我将这些文件上传到datatable时,我也得到了带有日期的时间列。我不想这样。我需要时间列只应该是时间只有日期。例如,我在excel表00:15:00中有时间值。当我上传到datatable我会得到02-02-2016 00:15:00这样。我想时间应该只保留时间。我怎么做?

Hi,

I have some datas in excel sheet which contains time only. But when i upload those file into datatable i got the time column with date also. I dont want like this. I need time column only should be time only with out date. For example, I have time value in excel sheet 00:15:00. When i upload this to datatable i will get 02-02-2016 00:15:00 like this. I want time should be keep time only. How i to do that?

推荐答案

Excel不存储时间。是的,您可以将Excel工作表格式化为仅显示时间,但在内部仍然存在日期值。



自Sql 2008起,sql具有列的Time数据类型。 time(Transact-SQL) [ ^ ]。所以,如果你要将它存储在SQL中,那么你可以只用时间把它写出来。



但是,如果你只是在工作在C#和你的DataTable中,这里有一堆不同的例子,说明如何从C#中的DateTime获得时间, datetime - 如何从日期时间C#获得时间 - Stack Overflow [ ^ ]。
Excel does not store just the time. Yes, you can format an Excel sheet to only show time but internally the date value is still there.

Since Sql 2008, sql has had a Time datatype for columns. time (Transact-SQL)[^]. So, if you are going to store this in SQL then you can write it out to sql with just the time.

However, if you are only going to be working with this in C# and your DataTable then here are a bunch of different examples of how to get just the time from a DateTime in C#, datetime - How to get only time from date-time C# - Stack Overflow[^].


这篇关于如何将Excel上传到数据表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆