Hi everyone, please i have the following problem and will be glade if anyone can help in any way to solve these problem. i have a report that is working on a web form that i design with asp.net 2.0 but the real problem is when i want to print from it by clicking the print icon button the page only refresh and come up with an empty page and it doesnt print. i always save my image to sql server 2005 and all is well, but trying to retrive this image back to the asp.net 2.0 image control is a big problem. please all any help will be grately appreciated.
1. i have a report that is working on a web form that i design with asp.net 2.0 but the real problem is when i want to print from it by clicking the print icon button the page only refresh and come up with an empty page and it doesnt print. Can you print the form correctly by going to the browsers File/Print settings? What is your code you have for your print button? 2. i always save my image to sql server 2005 and all is well, but trying to retrive this image back to the asp.net 2.0 image control is a big problem. Can you elaborate further on this issue? What is the error message that you are receiving? Can you give us the URL so that we can test it on our end?
Hi Freinds, the code for the crystalreport not print on asp.net 2.0 are: Imports System.Data.SqlClient Imports System.Data Imports System Imports System.Collections Imports CrystalDecisions.CrystalReports.Engine Imports CrystalDecisions.Shared Imports Microsoft.SqlServer.Server Partial Class _Default Inherits System.Web.UI.Page Dim DS As New DataSet Dim Comps As New GetComponents '------this is my database layer Dim DSST As New DS_StudentResultView Dim Tscore, TY As Integer : Dim nID As String 'Private WithEvents CryView As CrystalDecisions.CrystalReports Private Function GetGrade(ByVal Subject As String) '--------- Get the score of a student & process the Grade ----------- Try Dim Score, Grade Dim SQL As String = "Select * from tbl_ConAssement Where subject ='" & Trim(Subject) & "'" Using Con As New SqlConnection(Comps.SQLConnectionwW) Con.Open() Dim CMD As New SqlCommand(SQL, Con) Dim R As SqlDataReader = CMD.ExecuteReader While R.Read Score = R.Item("scores") End While R.Close() CMD.Dispose() Con.Close() End Using Dim Q As String = "Select * from tbl_gradeschame " Dim RUP, RLOW As Integer Using V As New SqlConnection(Comps.SQLConnectionwW) V.Open() Dim CMD As New SqlCommand(Q, V) Dim R As SqlDataReader = CMD.ExecuteReader While R.Read RUP = R.Item("upperRang") : RLOW = R.Item("LowerRang") If Score >= RUP And Score <= RLOW Then Grade = R.Item("Grade") End If End While V.Close() R.Close() CMD.Dispose() End Using Return Grade Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.OkOnly, "Error in search") Exit Function End Try End Function Private Sub Position(ByVal TT As Integer, ByVal ID As String) ' Return Void Dim Ary As New ArrayList Ary.Add(TT) Ary.Add(ID) 'Ary.Sort() End Sub Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Try DEL() '-------- Process the Result of a student --------------------- Dim SQL As String = "Select * from tbl_ConAssement Where Regno Like '" & TextBox1.Text.Trim & "%'" Using Con As New SqlConnection(Comps.SQLConnectionwW) Con.Open() Dim CMD As New SqlCommand(SQL, Con) Dim R As SqlDataReader = CMD.ExecuteReader While R.Read Dim Rec As DataRow DS = Comps.GetDataset("tbl_StudentReportView", "", "", "", "", 1) Rec = DS.Tables("tbl_StudentReportView").NewRow Rec!regno = R.Item("regno") Rec!firstname = R.Item("firstname") Rec!lastname = R.Item("lastname") Rec!subject = R.Item("subject") Rec!grade = GetGrade(R.Item("subject")) Rec!scores = R.Item("scores") Rec!term = R.Item("term") Rec!class = R.Item("class") Rec!sex = R.Item("sex") Rec!ca = R.Item("CA") Tscore += Rec!scores Rec!totalscore = Tscore DS.Tables("tbl_StudentReportView").Rows.Add(Rec) Comps.MyUPDATE(DS, "tbl_StudentReportView", 1) TY = Tscore nID = R.Item("regno") End While Position(TY, nID) TY = 0 R.Close() CMD.Dispose() Con.Close() End Using '------------ Show the Result Sheet of a student ------------- Dim DSST1 As New DataSet DSST1 = Comps.GetDataset("tbl_StudentReportView", "tbl_epay", "", "", "", 2) DSST.Merge(DSST1) Dim RepDoc As New ReportDocument Dim mypath As String = Server.MapPath("~/rpt_viewresult.rpt") RepDoc.Load(mypath) RepDoc.SetDataSource(DSST) CrystalReportViewer1.ReportSource = RepDoc CrystalReportViewer1.DataBind() CrystalReportViewer1.DisplayToolbar = True CrystalReportViewer1.DisplayGroupTree = False CrystalReportViewer1.DisplayPage = True CrystalReportViewer1.HasCrystalLogo = False CrystalReportViewer1.PrintMode = CrystalDecisions.Web.PrintMode.Pdf Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.OkOnly, "Error in search") Exit Sub End Try End Sub Private Sub printsMe() ' You can change more print options via PrintOptions property of ReportDocument Dim mypath As String = Server.MapPath("~/rpt_viewresult.rpt") Dim report As New ReportDocument() report.Load(mypath) report.PrintOptions.PaperSize = PaperSize.PaperA4 report.PrintToPrinter(1, True, 1, 1) report.Close() End Sub Private Sub DEL() Dim SQL As String = "Delete from tbl_StudentReportView" Comps.MyDELByData(SQL) End Sub Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click printsMe() End Sub End Class 2. I have remove the project from the web due to the problem. But I want you to know that is not throwing any exception error but it is not dipslay the image retrived from the sql server 2005 in the asp net 2.0 image control. But here is the code for this too. I get a web form that has asp2.0 image control and use the Image1.imageurl="web2.aspx". The web2.aspx will have the following codings. Imports System.Data.SqlClient Imports System.Data Imports System.IO Imports System.Drawing Imports System.Drawing.Imaging Partial Class ViewImage Inherits System.Web.UI.Page Dim DS As New DataSet Dim Comps As New GetComponents'------this is my database layer Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Try 'Get the all the printer that was install locally and in the Network 'DropDownList1.ClearSelection() 'DropDownList1.DataSource = System.Drawing.Printing.PrinterSettings.InstalledPrinters 'DropDownList1.DataBind() 'Dim MyByte() As Byte = KL.dr.Item("simage") 'CRead.Item("images") 'If MyByte.Length > 0 Then ' Dim myStream As New MemoryStream(MyByte, True) ' myStream.Write(MyByte, 0, MyByte.Length) ' Dim FinalImage As New Bitmap(myStream) ' If FinalImage.Width >= 217 And FinalImage.Height >= 151 Then ' PictureBox1.SizeMode = PictureBoxSizeMode.Zoom ' Dim Alte As New Bitmap(FinalImage, New Size(217, 151)) ' PictureBox1.Image = Alte ' Else ' PictureBox1.Image = FinalImage ' End If ' myStream.Close() 'End If Dim TeacherID = Session("TeacherId") Dim SQL As String = "Select * from tbl_TeacherReg Where TeacherID='" & TeacherID & "'" Using Con As New SqlConnection(Comps.SQLConnectionwW) Con.Open() Dim CMD As New SqlCommand(SQL, Con) Dim myStreams As MemoryStream Dim R As SqlDataReader = CMD.ExecuteReader While R.Read Dim MyBytes() As Byte = R.Item("simage") myStreams = New MemoryStream(MyBytes, True) myStreams.Write(MyBytes, 0, CInt(MyBytes.Length - 1)) If MyBytes.Length > 0 Then 'myStreams.Position = 1 Dim ImageBMPs As New Bitmap(myStreams, True) Context.Response.ContentType = "image/gif" ImageBMPs.Save(Context.Response.OutputStream, ImageFormat.Bmp) End If End While 'Dim myImage() As Byte = CType(CMD.ExecuteScalar, Byte) 'myStream.Position = 0 'Dim ImageBMP As Bitmap = New Bitmap(myStream) 'Context.Response.ContentType = "image/gif" 'ImageBMP.Save(Context.Response.OutputStream, ImageFormat.Bmp) End Using Catch ex As Exception Session.Item("muri") = ex.Message.ToString Page.Response.Redirect("errorpage.aspx", False) End Try End Sub End Class I will be much gratefull, You can realy Help out of this probs Thanks. Post Edited (abraham) : 7/25/2007 8:57:25 AM GMT