Quantcast
Channel: Oracle, MySQL, Sybase, Informix and other databases
Viewing all articles
Browse latest Browse all 1350

Get OleDb reading from excel to skip all empty rows.

$
0
0

I have been wracking my brain trying to figure out how to get OleDB to not import empty rows in my importable excel files.  It starts and will run perfectly fine until it hits an empty row and then it craps out.  Is there some way of doing this where if the row it is encountering it goes to the next row?  I am using a foreach loop.  The loop code looks like this:

                {
                    File.Copy(ExcelTempl, ExcelFile);
                    DirectoryInfo di = new DirectoryInfo(DropZone);
                    FileInfo[] fi = di.GetFiles("Master_*.xl*");
                    // step through each found file 
                    foreach (FileInfo fiTemp in fi)
                    {
                        {
                            // Connection String to Excel Workbooks
                            System.Threading.Thread.Sleep(1000);
                            string excelConnStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + DropZone + "\\" + fiTemp + "'; Extended Properties=\"Excel 8.0; HDR=YES; IMEX=1;\"";
                            WriteEvent("File Read", "Reading excel file " + fiTemp + " now.", "Automation User");
                            using (OleDbConnection connection = new OleDbConnection(excelConnStr))
                            {
                                connection.Open();
                                DataTable dt = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
                                if (dt != null)
                                {
                                    string[] excelSheets = new String[dt.Rows.Count];
                                    int i = 0;
                                    foreach (DataRow row in dt.Rows)
                                    { // I believe I need to do something right here

Any suggestions would be appreciated!


Viewing all articles
Browse latest Browse all 1350

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>