Hey Guys,
I have the same problem. But the differences is that my empty rows are in the middle and I have over 50 columns. The user wants to see the duplicated rows, so that means I cannot use SELECT DISTINCT * FROM [excel]
The empty rows could be anywhere. The largest excel I faced with so far have over 100,000 rows.
Is there a more efficient way to REMOVE the empty rows or MUST I loop through and check all columns in each row??
void SelectDataFromExcel()
{
string connectionString = ConfigurationSettings.AppSettings["ExcelConn"].ToString();
OleDbConnection excelConnection = new OleDbConnection(connectionString);
excelConnection.Open();
OleDbCommand dbCommand;
OleDbDataAdapter dataAdapter;
foreach (var sheet in Sheets)
{
dbCommand = new OleDbCommand("select DISTINCT* From[" + sheet + "$]", excelConnection);
System.Threading.Thread.Sleep(1000);
this.Invoke((MethodInvoker)delegate
{
listBox1.Items.Add("Tablo ismi: " + sheet.ToUpper(CultureInfo.InvariantCulture) + " Tablo Satır Sayısı: "+ dSet.Tables[sheet].Rows[0][0].ToString());
});
dataAdapter = new OleDbDataAdapter(dbCommand);
dTable = new DataTable();
dataAdapter.Fill(dTable);
dTable.TableName = sheet.ToUpper(CultureInfo.InvariantCulture);;
ArrangedDataList(dTable);
FillSqlTable(dTable, dTable.TableName);
dTable.Dispose();
dataAdapter.Dispose();
dbCommand.Dispose();
}
excelConnection.Close();
excelConnection.Dispose();
t1.Abort();
}