Deepak Goyal

Deepak Goyal

  • NA
  • 64
  • 0

exception in connecting the xls file in C# ASP .net

Jul 9 2009 5:45 AM
I an facing a problem if some one can help it will be greate.

 I have a XLS file as a database from which I want to get data.

        But every time VS 2005  comes out with an exception

The Microsoft Jet database engine could not find the object 'user_account$'.  Make sure the object exists and that you spell its name and the path name correctly.

my code is as below

public int verify_user(string filename, string user_passed)
    {

      
        String connectionString =
            "Provider=Microsoft.Jet.OLEDB.4.0;" +
            "Data Source=" + filename + ";" +
            "Extended Properties=Excel 8.0;";
        OleDbConnection connection = new OleDbConnection(connectionString);
        connection.Open();
        OleDbCommand selectCommand = new OleDbCommand("SELECT * FROM [user_account$]", connection);
        OleDbDataAdapter dataAdapter = new OleDbDataAdapter();
        dataAdapter.SelectCommand = selectCommand;
        DataSet dataSet = new DataSet();
        dataAdapter.Fill(dataSet);
        connection.Close();
       
       
        DataTable dataTable = dataSet.Tables[0];
        int cols = dataTable.Columns.Count;
       int rows_count= dataTable.Columns.Count;
       
       return rows_count;
        }


Answers (2)