hi all,
am developing windows application using c#.net ,
in this i have one part to click download and display file in excell sheet,
in this portion i have done in asp.net using c# but i need only windows application
i tryied my below asp.net code in to windows application but am couldnt get any similar code,
so please find out my below asp.net code and give me a windows application code,
its very appreciable for help....
my asp.net code is:
protected void download_Click(object sender, EventArgs e)
{
if (DDLCarrier.SelectedItem.Value == "DMSU")
{
SqlConnection con = new SqlConnection(ConnectionStr);
SqlCommand cmd = new SqlCommand("datadownload", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Destinations", SqlDbType.VarChar);
if (con.State == ConnectionState.Closed)
{
con.Open();
cmd.ExecuteNonQuery();
}
con.Close();
DataTable dt = Getdata(cmd);
GridView gv1 = new GridView();
gv1.AllowPaging = false;
gv1.DataSource = dt;
gv1.DataBind();
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
for (int i = 0; i < gv1.Rows.Count; i++)
{
gv1.Rows[i].Attributes.Add("class", "textmode");
}
gv1.RenderControl(hw);
string style = @"<style> .textmode { mso-number-format:\@; } </style>";
Response.Write(style);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
}
}
private DataTable Getdata(SqlCommand cmd)
{
DataTable dt = new DataTable();
SqlConnection con = new SqlConnection(ConnectionStr);
SqlDataAdapter da = new SqlDataAdapter();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = con;
try
{
con.Open();
da.SelectCommand = cmd;
da.Fill(dt);
return dt;
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
da.Dispose();
con.Dispose();
}
}