我正在尝试过滤数据并从我在目录中拥有的excel文件集合中创建新的excel文件。当前,我正在使用OLEDB命令,并且遇到错误数据类型不匹配的情况。我想知道是否可以使用epplus来完成,如果可以,请共享代码。
using (var xlConn = new OleDbConnection(cs))
{
xlConn.Open();
dtXlSchema = xlConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
for (int i = 0; i < dtXlSchema.Rows.Count; i++)
{
string sTableName = dtXlSchema.Rows[i]["Table_Name"].ToString();
string query ="Select [cs-uri-stem] from [" + sTableName + "] where ([cs-uri-stem] like '%" + kw + "%' and [sc-status] = '" + stat + "') Order by [cs-uri-stem]";
using (var cmd = new OleDbCommand(query, xlConn))
{
var rdr = cmd.ExecuteReader();
while (rdr.Read())
{
var row = dt.NewRow();
row["cs-uri-stem"] = rdr["cs-uri-stem"].ToString();
dtx.Rows.Add(row);
}
}
}