Bonjour;
je débute en asp.net je cherche à exportet les données d'une table sqlserver to une nouvelle feuille excel et pouvoir travailler normalement avec excel.
ce code n'affiche aucune erreur ni résultat non plus aidez moi s'il vs plait
file: 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];
} privatevoid 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;
foreach(DataColumn col
in table.
Columns) { colIndex++;
excel.
Cells[rowIndex, colIndex
] = row
[col.
ColumnName].
ToString();
} } excel.
Visible =
true;
} }