views:

60

answers:

1

i need your help to remove null and empty values in DataTable. My Excel table 4678 rows but returning rows more than 1000000 i need to remove empty or null ... Also MY COLUMNS COUNT 60!!! :( please help me

 foreach (var sheet in Sheets)
            {
                dbCommand = new OleDbCommand("select * 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);;
                bool isEmpty = true;

                for (int i = 0; i < dTable.Rows.Count; i++)
                {
                    isEmpty = true;
                    for (int j = 0; j < dTable.Columns.Count; j++)
                    {

                        if (string.IsNullOrEmpty(dTable.Rows[i][j].ToString()) == false)
                        {

                            isEmpty = false;
                            break;
                        }
                    }
                    if (isEmpty == true)
                    {
                        dTable.Rows.RemoveAt(i);
                        i--;
                    }
                }
                ArrangedDataList(dTable);
A: 

Excel remembers the last "visible/edited" cell. What you need to do is select cell A1, delete all the blank columns and rows, make sure cell A1 is still selected, save the workbook, then immediately exit Excel.

AMissico