none
Excel data import error?? RRS feed

  • Question

  • Dear Friends,

    I am using VS-2008 and C#, when I try to import excel data as given below I got an error stating "Sheet1$' is not a valid name.  Make sure that it does not include invalid characters or punctuation and that it is not too long." There is only one sheet in my workbook and the name is "06 Wigan (a) TACTICAL export", and the sheet does not have column name it uses the default columns lik A, B, C....etc.

    conString=@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\CoachingData Project Files\sample file.xls; Excel 8.0;HDR=Yes;IMEX=1;"

    strSQl=@"select * into [odbc; Driver={SQL server};Server=WIN-I5510BB2O9X\COACHINGDATA;Database=SAClubDb;].XLImports9 FROM [Sheet1$] where playernames is not null"

    OleDbConnection cnCSV = new OleDbConnection(strConnectionString);
                    cnCSV.Open();
                    OleDbCommand cmdInsert = new OleDbCommand(strSQl, cnCSV);
                    cmdInsert.ExecuteNonQuery();


    Is there any fix for this? Need your help.

    Thanks

    Monday, October 6, 2008 5:33 AM

Answers

  • You need to specify the exact Worksheet name, usually following by the $ character. So you should be using [06 Wigan (a) TACTICAL export$] instead of [Sheet1$]. Also, if there are no column names in the first row of Worksheet you need to use the default column names F1, F2, F3, etc.

    Monday, October 6, 2008 1:38 PM