I have a Stored Procedure
Create procedure selectdata
as
begin
select * from Employee
end
In my front End I Created a Button in default.aspx page
<asp:Button id="btnsave" runat="server" Text="Send to Excel" onclick="btnsave_Click"/> <asp:GridView id="gv" runat="server" > </asp:GridView>
In default.aspx.cs
protected void btnsave_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString="User id=aa; password=123; Initial Catalog=abc;Integrated Security=xxxx";
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "selectdata";
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
gv.DataSource = ds;
gv.DataBind();
}
Output: It Displays the Data in Grid View
but is it possible to store the Data directly in Excel file in my PC