I want import data from sqlserver to excel ;
When I click on the button I have no results,where is the problemfile: default.aspx.cs
using System;
using System.Drawing;
using System.Data;
using System.Data.SqlClient;
public partial class Default4 : System.Web.UI.Page
{
private System.Data.DataTable GetData()
SqlConnection conn = new SqlConnection(@"server=(.\SQLEXPRESS);uid=sa;pwd=xxxx;database=examen.mdf;");
SqlDataAdapter adapter = new SqlDataAdapter("select * from ETUDIANT", conn);
DataSet myDataSet = new DataSet();
try
adapter.Fill(myDataSet, "ETUDIANT");
}
catch (Exception ex)
return myDataSet.Tables[1];
private void button1_Click(object sender, System.EventArgs e)
Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
int rowIndex = 1;
int colIndex = 0;
excel.Application.Workbooks.Add(true);
DataTable table = GetData();
foreach (DataColumn col in table.Columns)
colIndex++;
excel.Cells[1, colIndex] = col.ColumnName;
foreach (DataRow row in table.Rows)
rowIndex++;
colIndex = 0;
excel.Cells[rowIndex, colIndex] = row[col.ColumnName].ToString();
excel.Visible = true;