Click here to Skip to main content
15,914,488 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My code as follows

private void Preseaintake()
{
try
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "Presea_Intakerpts '" + dtfromdate.Text.Trim() + "', '" + dttodate.Text.Trim() + "'";
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adp.Fill(dt);
string filename = "E:\\Preseaintake\\10032014_PreseaIntakedetails.xls";
System.IO.StreamWriter file = new System.IO.StreamWriter(filename);
file.Close();

}

catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK);
return;
}

}

i have written a store procecdure, that store procedure value has been binded using datatable.


Now i wan to bind the datatable records into excel.

for that how can i do using c#.

Please help me.

regards,
Narasiman P.
Posted

1 solution

Do have a look at the following solution, which exports the datatable to csv format which is supported by Excel, You can just change the contenttype to export it to Excelformat.


Export DataTable using C#
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900