Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. want to fransfer datas from sql server to excel

want to fransfer datas from sql server to excel

Scheduled Pinned Locked Moved ASP.NET
databasecsharpasp-netsql-server
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Deepthy P M
    wrote on last edited by
    #1

    I am using asp.net+vb.net I want to export datas from sqlserver to excel.I wrote code for that.My it display in the internet explorer same page. I want to display in another page and want to set only print button for that page. The code i wrote is given below. ***************** Private Sub BindReport() If Session("Rep") Is Nothing Then Dim ConnInfo As New ConnectionInfo With ConnInfo .ServerName = "User1" .DatabaseName = "IMS" .UserID = "sa" .Password = "" End With Dim rep As New ReportDocument rep.Load(Server.MapPath("Crystalreport2.rpt")) Me.CrystalReportViewer1.ReportSource = rep Dim RepTbls As Tables = rep.Database.Tables For Each RepTbl As Table In RepTbls Dim RepTblLogonInfo As TableLogOnInfo = RepTbl.LogOnInfo RepTblLogonInfo.ConnectionInfo = ConnInfo RepTbl.ApplyLogOnInfo(RepTblLogonInfo) Next Session("Rep") = rep End If Me.CrystalReportViewer1.ReportSource = Session("Rep") Me.CrystalReportViewer1.DataBind() End Sub ************************** Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then BindReport() Me.CrystalReportViewer1.ShowFirstPage() End If end sub ****************************** Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click crReportDocument = New ReportDocument() crReportDocument.Load(Server.MapPath("crystalreport2.rpt")) Fname = "C:\exports\" & Session.SessionID.ToString & ".xls" crDiskFileDestinationOptions = New DiskFileDestinationOptions() crDiskFileDestinationOptions.DiskFileName = Fname crExportOptions = crReportDocument.ExportOptions With crExportOptions .DestinationOptions = crDiskFileDestinationOptions .ExportDestinationType = ExportDestinationType.DiskFile .ExportFormatType = ExportFormatType.PortableDocFormat End With crReportDocument.Export() Dim oStream As New MemoryStream oStream = crReportDocument.ExportToStream(ExportFormatType.Excel) oStream = crReportDocument.ExportToStream(ExportFormatType.Excel) report.ExportToStream(CrystalDecisions.Shared.ExportFor

    K 1 Reply Last reply
    0
    • D Deepthy P M

      I am using asp.net+vb.net I want to export datas from sqlserver to excel.I wrote code for that.My it display in the internet explorer same page. I want to display in another page and want to set only print button for that page. The code i wrote is given below. ***************** Private Sub BindReport() If Session("Rep") Is Nothing Then Dim ConnInfo As New ConnectionInfo With ConnInfo .ServerName = "User1" .DatabaseName = "IMS" .UserID = "sa" .Password = "" End With Dim rep As New ReportDocument rep.Load(Server.MapPath("Crystalreport2.rpt")) Me.CrystalReportViewer1.ReportSource = rep Dim RepTbls As Tables = rep.Database.Tables For Each RepTbl As Table In RepTbls Dim RepTblLogonInfo As TableLogOnInfo = RepTbl.LogOnInfo RepTblLogonInfo.ConnectionInfo = ConnInfo RepTbl.ApplyLogOnInfo(RepTblLogonInfo) Next Session("Rep") = rep End If Me.CrystalReportViewer1.ReportSource = Session("Rep") Me.CrystalReportViewer1.DataBind() End Sub ************************** Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then BindReport() Me.CrystalReportViewer1.ShowFirstPage() End If end sub ****************************** Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click crReportDocument = New ReportDocument() crReportDocument.Load(Server.MapPath("crystalreport2.rpt")) Fname = "C:\exports\" & Session.SessionID.ToString & ".xls" crDiskFileDestinationOptions = New DiskFileDestinationOptions() crDiskFileDestinationOptions.DiskFileName = Fname crExportOptions = crReportDocument.ExportOptions With crExportOptions .DestinationOptions = crDiskFileDestinationOptions .ExportDestinationType = ExportDestinationType.DiskFile .ExportFormatType = ExportFormatType.PortableDocFormat End With crReportDocument.Export() Dim oStream As New MemoryStream oStream = crReportDocument.ExportToStream(ExportFormatType.Excel) oStream = crReportDocument.ExportToStream(ExportFormatType.Excel) report.ExportToStream(CrystalDecisions.Shared.ExportFor

      K Offline
      K Offline
      kumareshTMC
      wrote on last edited by
      #2

      Imports System.IO Partial Class _Default Inherits System.Web.UI.Page Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged End Sub Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Response.Clear() Response.AddHeader("content-disposition", String.Format("attachment;filename={0}.xls", "tmc.xls")) 'Response.AddHeader("content-disposition", String.Format("attachment;filename={0}", "kumaresh")) Response.Charset = "" Response.Cache.SetCacheability(HttpCacheability.NoCache) 'Response.ContentType = "application/ms-excel" Response.ContentType = "application/" Dim stringWrite As New StringWriter() Dim htmlWrite As New HtmlTextWriter(stringWrite) GridView1.RenderBeginTag(htmlWrite) GridView1.RenderControl(htmlWrite) GridView1.RenderEndTag(htmlWrite) Response.Write(stringWrite.ToString()) Response.End() End Sub Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control) End Sub

      D 1 Reply Last reply
      0
      • K kumareshTMC

        Imports System.IO Partial Class _Default Inherits System.Web.UI.Page Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged End Sub Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Response.Clear() Response.AddHeader("content-disposition", String.Format("attachment;filename={0}.xls", "tmc.xls")) 'Response.AddHeader("content-disposition", String.Format("attachment;filename={0}", "kumaresh")) Response.Charset = "" Response.Cache.SetCacheability(HttpCacheability.NoCache) 'Response.ContentType = "application/ms-excel" Response.ContentType = "application/" Dim stringWrite As New StringWriter() Dim htmlWrite As New HtmlTextWriter(stringWrite) GridView1.RenderBeginTag(htmlWrite) GridView1.RenderControl(htmlWrite) GridView1.RenderEndTag(htmlWrite) Response.Write(stringWrite.ToString()) Response.End() End Sub Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control) End Sub

        D Offline
        D Offline
        Deepthy P M
        wrote on last edited by
        #3

        i am using crystal report in this code.My program working properly but i want to display only print button in toolbar not other toolbar buttons. I also want to export this crystal report details in word. How can i do this.Pls help

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups