SqlCommand cmd = new SqlCommand(strQuery) String strQuery = "select CustomerID, ContactName, City, PostalCode" + Get the data from database into datatable Protected void ExportToExcel( object sender, EventArgs e) Also you will notice I applied textmode style to all the rows so that it in rendered as text. It first fills the datatable using the GetData function and then binds it to a dummy GridView and then the dummy GridView is rendered as Excel Workbook. The figure below displays the generated Microsoft Word Document.īelow is the code to export the datatable to Excel Format. Response.ContentType = "application/vnd.ms-word " Response.AddHeader( "content-disposition", _ 'Get the data from database into datatableĭim strQuery As String = "select CustomerID, ContactName, City, " & _ Protected Sub ExportToWord( ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExportWord.Click
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |