111,120
社区成员
发帖
与我相关
我的任务
分享
public static DataSet ExecuteDataSet(OleDbConnection cn, params string[] sheetNames)
{
DataSet ds = new DataSet();
DataTable schemaTable = cn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
string queryString;
string fullTableName;
string realTableName;
OleDbDataAdapter odda = new OleDbDataAdapter();
foreach (DataRow dr in schemaTable.Rows)
{
fullTableName = dr["TABLE_NAME"].ToString();
realTableName = fullTableName.Remove(fullTableName.Length - 1, 1);
if (sheetNames.Length > 0)
{
if (Array.IndexOf(sheetNames, realTableName) < 0)
{
continue;
}
}
queryString = string.Format("SELECT * FROM [{0}]", fullTableName);
odda.SelectCommand = new OleDbCommand(queryString, cn);
odda.Fill(ds, realTableName);
}
return ds;
cn.Close();
}