I am trying to export to excel from sql server database using Microsoft.Office.Interop.Excel;

But I am getting an error:

> 
> microsoft.office.interop.excel.application does not contain a
>  definition for 'workbooks' and no extension method 'workbooks'
> 
> 
> 

I have added all the required references too. Please let me know how can I solve the issue.

P.S- also getting same error for SaveAs.

```
void ExportToExcel(string sqlquery, string filename)
        {
            Cursor.Current = Cursors.WaitCursor;
            SqlConnection cnn;
            string connectionString = null;
            string sql = null;
            string data = null;
            int i = 0;
            int j = 0;

            Excel.Application xlApp;
            Excel.Workbook xlWorkBook;
            Excel.Worksheet xlWorkSheet;
            object misValue = System.Reflection.Missing.Value;

            xlApp = new Excel.ApplicationClass();
            xlWorkBook = xlApp.Workbooks.Add(misValue);
            xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);

            connectionString = "Data Source=HULMOSSPROD;Initial Catalog=" + cbx_Settings.Text + ";User Id=mosssa;Password=Unilever123;";
            cnn = new SqlConnection(connectionString);
            cnn.Open();
            sql = sqlquery;
            SqlDataAdapter dscmd = new SqlDataAdapter(sql, cnn);
            DataSet ds = new DataSet();
            dscmd.Fill(ds);

            //==============================================================================================================
            string strLine;

            SqlCommand cmd = new SqlCommand(sqlquery, cnn);
            SqlDataReader dr;
            dr = cmd.ExecuteReader();

            //Initialize the string that is used to build the file.
            strLine = "";

            //Enumerate the field names and the records that are used to build 
            //the file.
            for (int m = 0; m < 1; m++)
            {
                for (int k = 0; k <= dr.FieldCount - 1; k++)
                {

                    strLine = dr.GetName(k).ToString();
                    //xlWorkSheet.Cells[m + 1, k + 1] = strLine;

                }
            }
            //==============================================================================================================

            for (i = 1; i <= ds.Tables[0].Rows.Count; i++)
            {
                for (j = 0; j <= ds.Tables[0].Columns.Count - 1; j++)
                {
                    data = ds.Tables[0].Rows[i - 1].ItemArray[j].ToString();
                    //xlWorkSheet.Cells[i + 1, j + 1] = data;
                }
            }

            xlWorkBook.SaveAs("C:\\80IB_Reports\\" + filename, Excel.XlFileFormat.xlWorkbookDefault, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
            xlWorkBook.Close(true, misValue, misValue);
            xlApp.Quit();
            cnn.Close();

            releaseObject(xlWorkSheet);
            releaseObject(xlWorkBook);
            releaseObject(xlApp);
            Cursor.Current = Cursors.Default;

            MessageBox.Show("Export Successful. You can find the file at C:\\80IB_Reports");

        }

```