i am trying to import data from db to excel sheet using excel sheet,its work fine,but problem is that there is a fixed path where i can save a copy,but my requirement is that i have to import multiple sheet base on multiple queries,so i want to use savedialoguebox to save these file with different name and different location,how is it possible?my code is as follow
Hide Expand Copy Code
Code
string connectionstring = null;
Code
   string sql = null;
Code
                            string data = null;
Code
                          int i = 0;
Code
                          int j = 0;
Code
                            Microsoft.Office.Interop.Excel.Application xlApp;
Code
                           Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
Code
                           Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;
Code
                           object misValue = System.Reflection.Missing.Value;
Code
Code
                             xlApp = new Microsoft.Office.Interop.Excel.Application();
Code
                          xlWorkBook = xlApp.Workbooks.Add(misValue);
Code
                      xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
Code
                            connectionstring = "Data Source=(local);Initial Catalog=Report_Database;integrated security=True";
Code
                           cnn = new SqlConnection(connectionstring);
Code
                          cnn.Open();
Code
      sql = "SELECT * FROM Report_Tab";
Code
                         SqlDataAdapter dscmd = new SqlDataAdapter(sql, cnn);
Code
                       DataSet ds = new DataSet();
Code
                           dscmd.Fill(ds);
Code
                           for (i = 0; i 0].Rows.Count - 1; i++)
Code
                        {
Code
                              for (j = 0; j 0].Columns.Count - 1; j++) {
Code
  data = ds.Tables[0].Rows[i].ItemArray[j].ToString();
Code
                                  xlWorkSheet.Cells[i + 1, j + 1] = data;
Code
                            }
Code
                 }
Code
         xlApp.ActiveWorkbook.SaveCopyAs("C:\\Users\\sajid\\Desktop\\test.xls");
Code
                    xlApp.ActiveWorkbook.Saved = true;
Code
  xlApp.Quit();
Code
           releaseObject(xlWorkSheet);
Code
          releaseObject(xlWorkBook);
Code
         releaseObject(xlApp);
Code
    MessageBox.Show("Excel file created , you can find the file D:\\Sam-informations.xls");