views:

41

answers:

1

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();
        }
A: 

one way to achive is to check for empty value

DataView dv = null;
dv = new DataView();

{
    dv.Table = myDatatable;
    dv.AllowDelete = true;
    dv.AllowEdit = true;
    dv.AllowNew = true;
    dv.RowFilter = "myField = ' '";
}
Pranay Rana
What can i write instead of "myField". My Column's count more than 60!!! :(
Phsika
you name of column of your table
Pranay Rana
How can i do for more columns?
Phsika
use and clause or "or" clause in rowfilter
Pranay Rana