我是 C# 新手,我有一个 C# 程序和一个从另一个程序导出的 excel 文件。如何将其转换为日期时间?这是代码,其中dtFrom
和dtTo
是DateTimePicker
变量:
System.Data.DataTable dtExcel = new System.Data.DataTable();
dtExcel.TableName = "MyExcelData";
string SourceConstr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + this.textBox1.Text + "';Extended Properties= 'Excel 8.0;HDR=Yes;IMEX=1'";
OleDbConnection con = new OleDbConnection(SourceConstr);
string query = "Select Customer, SUM(Wt) AS Weight from [Sheet0$] WHERE (CONVERT(datetime, [Date]) >= " + this.dtFrom.Value.Month + ") GROUP BY Customer order by Customer";
OleDbDataAdapter data = new OleDbDataAdapter(query, con);
data.Fill(dtExcel);