将Excel日期列读取为文本 [英] Reading Excel date column as Text
问题描述
大家好,
我将excel数据填充到数据库表中。我这样做是通过将excel数据加载到数据表并将数据表值存储到SQL表中,如下所示。
Hi All,
I am filling the excel data to a database table. I am doing this by loading the excel data to a datatable and storing datatable value to SQL table as below.
OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + ExcelSource + ";Extended Properties=Excel 8.0;");
//Dim myTableName = myConn.GetSchema("Tables").Rows(0)("TABLE_NAME")
con.Open();
string tblSheetnames = (string) con.GetSchema("Tables").Rows[0]["TABLE_NAME"];
//String.Format("SELECT * FROM [{0}]", myTableName), myConn
string excelQuery=String.Format("SELECT * FROM [{0}]", tblSheetnames);
OleDbDataAdapter da = new OleDbDataAdapter(excelQuery, con);
dt = new DataTable();
da.Fill(dt);
在excel中我有一个日期列(dd \\\\yyyy),从我的这个列读完之后C#代码在adatatable中它将时间组件添加到上午12:00作为DD \\\YYYY 12 AM。
任何人都可以帮助我如何通过更新我提到的代码获取日期作为文本。
谢谢和问候
Prashant
In the excel I have a date column(dd\mm\yyyy), after reading this column from my C# code in adatatable it is adding time component 12:00 AM as "DD\MM\YYYY 12 AM".
Can any one help me how do I get the date as text by updating the code I mentioned.
Thanks And Regards
Prashant
推荐答案
你读取的excel文件make new column time =
The excel file that you read from make new column time =
=TEXT(A2,"hh:mm")
并从中读取。(A2是旧时间栏);
and read from it.(A2 is the old time column);
这篇关于将Excel日期列读取为文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!