why is it be error: "Not a legal OleAut" when importing Excel2007 into SQL 2005 ?


why is it be error: "Not a legal OleAut" when importing Excel2007 into...
Author
Message
Dong Trien Lam
Dong Trien Lam
StrataFrame User (173 reputation)StrataFrame User (173 reputation)StrataFrame User (173 reputation)StrataFrame User (173 reputation)StrataFrame User (173 reputation)StrataFrame User (173 reputation)StrataFrame User (173 reputation)StrataFrame User (173 reputation)StrataFrame User (173 reputation)
Group: Anonymous / Guest
Posts: 57, Visits: 251
I am be an error importing the Excel2007: "Not a legal OleAut date", you see my code below:

public static void ImportToSql(string excelfilepath)
        {
            string ssqltable = "TABHD";
            string myexceldataquery = "SELECT * FROM [dbo_TABHD]";
            try
            {
                string sexcelconnectionstring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source =" + excelfilepath + "; Extended Properties=\"Excel 12.0; HDR=Yes; IMEX=2\"";
                string ssqlconnectionstring = @"server = itfriend;Database=HD;integrated security = true";
 
                //execute a query to erase any previous data from our destination table
                string sclearsql = "delete " + ssqltable;
                INSERTING IT.INSTEAD I WANT TO UPDATE TABLE DATA"
                SqlConnection sqlconn = new SqlConnection(ssqlconnectionstring);                
 
                OleDbConnection oledbconn = new OleDbConnection(sexcelconnectionstring);
                OleDbCommand oledbcmd = new OleDbCommand(myexceldataquery, oledbconn);
                oledbconn.Open();
                OleDbDataReader dr = oledbcmd.ExecuteReader();
                SqlBulkCopy bulkcopy = new SqlBulkCopy(ssqlconnectionstring);
                bulkcopy.DestinationTableName = ssqltable;
 
                bulkcopy.WriteToServer(dr); // Eror in here: "Not a legal OleAut date"
 
                Console.WriteLine(".xlsx file imported succssessfully into database.", bulkcopy.NotifyAfter);
                oledbconn.Close();
            }
            catch (Exception ex)
            {
                //handle exception
                MessageBox.Show(ex.Message.ToString(), "Warning !");
            }
        }

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search