I have created a WebMethod that saves records into a database and call a print function to print a crystal report document. i get this error when the print function is called by the web method.
Error BC30369 Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class.
Public Function print(receipt)
Dim crtableLogoninfos As New TableLogOnInfos
Dim crtableLogoninfo As New TableLogOnInfo
Dim crConnectionInfo As New ConnectionInfo
Dim CrTables As Tables
Dim CrTable As Table
Dim crystalReport As ReportDocument
crystalReport = New ReportDocument()
crystalReport.Load(Server.MapPath("Reports/rptReceipt.rpt"))
crystalReport.SetParameterValue("RECEIPT", receipt)
Dim conStringReport As String = ConfigurationManager.ConnectionStrings("conString").ConnectionString
Dim connStringBuilder As SqlConnectionStringBuilder = New SqlConnectionStringBuilder(conStringReport)
Dim myConnectionInfo As ConnectionInfo = New ConnectionInfo()
myConnectionInfo.ServerName = connStringBuilder.DataSource
myConnectionInfo.DatabaseName = connStringBuilder.InitialCatalog
myConnectionInfo.UserID = connStringBuilder.UserID
myConnectionInfo.Password = connStringBuilder.Password
CrTables = crystalReport.Database.Tables
For Each CrTable In CrTables
crtableLogoninfo = CrTable.LogOnInfo
crtableLogoninfo.ConnectionInfo = myConnectionInfo
CrTable.ApplyLogOnInfo(crtableLogoninfo)
Next
Dim stream As New BinaryReader(crystalReport.ExportToStream(ExportFormatType.PortableDocFormat))
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"
Response.BinaryWrite(stream.ReadBytes(Convert.ToInt32(stream.BaseStream.Length)))
Response.Flush()
Response.Close()
End Sub
<WebMethod()>
<ScriptMethod()>
Public Shared Function SaveReceipt(ByVal Feespayments As Feespayments) As Feespayments
Dim strConnString As String = ConfigurationManager.ConnectionStrings("conString").ConnectionString
Dim con As SqlConnection = New SqlConnection(strConnString)
Dim cmd As SqlCommand = New SqlCommand
cmd.Connection = con
cmd.CommandText = "FEES_PAYMENT"
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@STATEMENT_TYPE", "INSERT")
cmd.Parameters.AddWithValue("@STUDENT_ID", Feespayments.STUDENT_ID)
cmd.Parameters.AddWithValue("@TERM_CODE", Feespayments.TERM_CODE)
cmd.Parameters.AddWithValue("@ACCADEMIC_YEAR", Feespayments.ACCADEMIC_YEAR)
cmd.Parameters.AddWithValue("@RECIEPT_TYPE", Feespayments.RECIEPT_TYPE)
cmd.Parameters.AddWithValue("@AMOUNT_PAID", Feespayments.AMOUNT_PAID)
cmd.Parameters.AddWithValue("@TUSER", Feespayments.TUSER)
cmd.Parameters.AddWithValue("@PAYMENT_TYPE", Feespayments.PAYMENT_TYPE)
cmd.Parameters.AddWithValue("@PAYMENT_NUMBER", Feespayments.PAYMENT_NUMBER)
cmd.Parameters.AddWithValue("@BILL_ID", Feespayments.BILL_ID)
cmd.Parameters.AddWithValue("@ITEM_CODE", Feespayments.ITEM_CODE)
cmd.Parameters.AddWithValue("@ITEM", Feespayments.ITEM)
cmd.Parameters.AddWithValue("@TSTATUS", Feespayments.TSTATUS)
cmd.Parameters.AddWithValue("@TRANS_TYPE", Feespayments.TRANS_TYPE)
cmd.Parameters.AddWithValue("@DEBIT", Feespayments.DEBIT)
cmd.Parameters.AddWithValue("@CREDIT", Feespayments.CREDIT)
cmd.Parameters.AddWithValue("@INSTITUTION", Feespayments.INSTITUTION)
cmd.Parameters.AddWithValue("@RECIEPT", Feespayments.receipt)
con.Open()
cmd.ExecuteNonQuery()
print(Feespayments.receipt)
Return Feespayments
con.Close()
End Function