locked
How to apply range in excel using asp.net c# RRS feed

  • Question

  • User840052993 posted

    using (OleDbDataAdapter oda = new OleDbDataAdapter("SELECT * From [" + sheet1 + "A2:B6]", excel_con))
    {
    oda.Fill(dtExcelData);
    }

    this statement gives me  the error,i dont knw how to apply range

     plz help me

    Tuesday, March 10, 2015 5:44 AM

All replies

  • User1644755831 posted

    Hi vjnithin,

    The format is like this

     "SELECT * FROM [<SheetName>$<optional range>]";

    So you can do it like this

    "SELECT * FROM [MySheet$A2:B6]";
    

    Hope this helps,

    With Regards,

    Krunal Parekh

    Tuesday, March 10, 2015 6:25 AM
  • User840052993 posted

    But how do i get the range values A2:B6,

    do i nned to use  Microsoft.Office.Interop.Excel; 

    Tuesday, March 10, 2015 6:48 AM
  • User1644755831 posted

    Hi vjnithin,

    From your code , as you are using Oledb just change your code like this.

    using (OleDbDataAdapter oda = new OleDbDataAdapter("SELECT * FROM [" + sheet1 + "$A2:B6]", excel_con))
     {
       oda.Fill(dtExcelData);
     }
    

    It should work.

    Hope this helps.

    With Regards,

    Krunal Parekh

    Tuesday, March 10, 2015 10:31 PM
  • User840052993 posted

    The Microsoft Access database engine could not find the object ''GA-Traffic data$'$A2:L6'. Make sure the object exists and that you spell its name and the path name correctly. If ''GA-Traffic data$'$A2:L6' is not a local object, check your network connection or contact the server administrator.

    Its showing this error

    Wednesday, March 11, 2015 9:11 AM