【发布时间】:2019-05-16 13:44:06
【问题描述】:
我正在使用下面的 select 语句从 excel 中提取数据并将其放入数据表中。那里有一个我不想接的坏行,所以这就是这部分 [Plan] 'PLAN_BO' 但是它不适用于其他两个 OR 语句。 [Plan] 应该是一个日期时间列,但有一个额外的文本行。
[Plan] 'PLAN_BO' 或 [Plan] 的组合是 null 一起工作,但不是三个一起工作。
comm.CommandText = "Select Category, [Project ID], Package, [Design ID], LLW, Bldg, School, [Project Description], [Doc Avail], [Plan] from [ca_rpt$] where [Plan] <> 'PLAN_BO' or [Plan] is null or [Plan] >= DATE() order by Category, [Project ID], Package, [Design ID], LLW";
有没有办法抵消第一行,因为那是坏行,但不是列标题。我在语句末尾尝试了 Offset 1 Row,但它不起作用。
编辑:当前状态
(ISDATE([Bid Open Plan]) and [Bid Open Plan] >= DATE()) or [Bid Open Plan] 为空
[开标计划] >= DATE() 被忽略。
using (OleDbConnection conn = new OleDbConnection())
{
System.Data.DataTable dt = new System.Data.DataTable();
conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";" + "Extended Properties='Excel 12.0 Xml;HDR=YES;IMEX=1'";
using (OleDbCommand comm = new OleDbCommand())
{
comm.CommandText = "Select Category, [Project ID], Package, [Design ID], LLW, Bldg, School, [Project Description], [Pkg#], [Doc Available], [Bid Open Plan] from(Select Category, [Project ID], Package, [Design ID], LLW, Bldg, School, [Project Description], [Pkg#], [Doc Available], [Bid Open Plan] from [ca_rpt$] where ISDATE([Bid Open Plan]) or [Bid Open Plan] is null) Where [Bid Open Plan] >= DATE() order by Mincat, Minse, [Pkg#], [Project ID], Package, [Design ID], LLW";
comm.Connection = conn;
using (OleDbDataAdapter da = new OleDbDataAdapter())
{
da.SelectCommand = comm;
da.Fill(dt);
【问题讨论】:
标签: c# sql excel sqlcommand