Monday, July 12, 2010

Export GridView Data into Excel in C# .Net

Export GridView Data into Excel in C# .Net

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);
GridView1.RenderControl(hw);//DataGrid Name
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();

Stored procedure to Attach Database in SQL Server 2005

just write given sp in new query window

sp_attach_single_file_db
@dbname= 'databasename', @physname= '.mdf file path'

and execute that
ur database will be successfully created