Crystal Reports- Export report causing "Missing Parameter Values" - asp.net

I am trying to export a report but everytime it runs the code to export the crystal report in the crystalreportviewer I get an error message saying "Missing Parameter Values". I've looked through many sources but havent found a solution. I do know that all parameters are filled in because without the export code, the site runs perfectly fine.
Export code
Try
Dim CrExportOptions As CrystalDecisions.Shared.ExportOptions
Dim CrDiskFileDestinationOptions As New _
CrystalDecisions.Shared.DiskFileDestinationOptions()
Dim CrFormatTypeOptions As New CrystalDecisions.Shared.PdfRtfWordFormatOptions()
CrDiskFileDestinationOptions.DiskFileName = _
"c:\crystalExport.pdf"
CrExportOptions = oRpt.ExportOptions
With CrExportOptions
.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile
.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat
.DestinationOptions = CrDiskFileDestinationOptions
.FormatOptions = CrFormatTypeOptions
End With
oRpt.Export()
Catch ex As Exception
Response.Write(ex.ToString)
End Try
Also:
'Try
' oRpt.ExportToHttpResponse([Shared].ExportFormatType.PortableDocFormat, Response, True, "ExportedReport")
'Catch ex As Exception
' Response.Write(ex.ToString)
'End Try
Any help would be great.

This is caused under 2 reasons.
Either, you're not passing(from the program) a required parameter which you have created in the report.
Or, you're passing a parameter to the report but you haven't created it in the report.

To solve my own problem I found that the code actually exports the instance of the crystal report, whereas I was putting the parameters into the crystalreportviewer after providing the source. Instead I provided the parameters directly into the instance which gets pushed into the crystalreportviewer as a datasource.
:)

In my case, there was a subreport that was not correctly linked with the main report.
Check if all the parameters of the subreport is linked with the main report.
Cheers;

Have to set required parameters
Set rpt.SetDataSource(dt) even DataTable records count is 0:
DataTable dt = new DataTable();
dt.Load(data);
if (dt?.Rows != null)
{
rpt.SetDataSource(dt);
return true;
}

Related

Error when using the WHERE clause in Linq-to-SQL

I have a datacontext that I'm trying to query, the results of which I want to bind to a gridview on a button click. Getting connected to the datacontext works great. I get the 1000s of records I expect. When I try to add the WHERE clause, I run into problems. Here's the button event I'm trying to make it happen at:
Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim dsource = New MY_DataContext().SV_XXXs '--- This works, the data is all there
gridRec.DataSource = dsource.ToList().Where(Function(dtable) dtable.PN = Session("PN")) '--- this fails
'--- Also tried this, it also did not work ----------------------------------------------------------
'--- gridRec.DataSource = dsource.Where(Function(dtable) dtable.PN = Session("PN")) '--- this fails
'----------------------------------------------------------------------------------------------------
gridRec.DataBind()
End Sub
The session variable is valid and the dsource is populating correctly, but I get the following error when it tries to execute the Where clause:
Evaluation of method
System.Linq.SystemCore_EnumerableDebugView`1[SV_REC].get_Items() calls
into native method System.WeakReference.get_Target(). Evaluation of
native methods in this context is not supported.
Also tried:
Dim results =
(
From T In dsource
Where T.PN = Session("SAFRReceiverPN")
Select T
).ToList
And get this error
Method 'System.Object CompareObjectEqual(System.Object, System.Object,
Boolean)' has no supported translation to SQL.
And tried:
Dim results = From t In dsource Where (t.PN = Session("SAFRReceiverPN")) Select t
nothing seems to work for me when trying a WHERE clause
C# or VB.NET are both cool if you have any suggestions.
Really, any help is appreciated, thanks.
LINQ to SQL doesn't know what to do when you try to access the session inside the query. Instead of doing that, fetch the value from the session before the query and store the result in a local variable, then use that local variable in your query. For example, in C#:
var receiver = (string) Session["SAFRReceiverPN"];
var results = dsource.Where(t => t.PN == receiver);
(I don't bother with query expressions when you're just trying to perform a simple filter.)

Crystal Report direct saving as PDF, instead of viewing

I want to make a report from ASP.Net, in Crystal Report. I want, when user click on print, it should simply show a browser dialog of Save,Open,Save as, and PDF should be saved, or Crystal Report print preview should appear, I don't want to display report first in Viewer then click on button to get print or PDF, I want simply from clicking on asp button, I have all the idea of parameters and know how to make report, my question is just to not to show viewer and take report from asp button in a form of PDF or print preview dialog to print. I have used the Export method of .Net for Crystal Report, but it does not work.
You can generate a PDF by Using a Crystal Report and piece of code....
First: Generate a Crystal Report as per your requirements.
Second: Use the below code to generate the PDF:
Place the following name spaces at the top of the code page
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Variable Declaration
Dim CrReport As New CrystalReport1() // Report Name
Dim CrExportOptions As ExportOptions
Dim CrDiskFileDestinationOptions As New DiskFileDestinationOptions()
Dim CrFormatTypeOptions as New PdfRtfWordFormatOptions()
Set the destination path and file name
CrDiskFileDestinationOptions.DiskFileName = "c:\RichText.pdf"
Specify a page range (optional)
crFormatTypeOptions.FirstPageNumber = 1 // Start Page in the Report
crFormatTypeOptions.LastPageNumber = 3 // End Page in the Report
crFormatTypeOptions.UsePageRange = True
Set export options
CrExportOptions = crReport.ExportOptions
With CrExportOptions
// Set the destination to a disk file
.ExportDestinationType = ExportDestinationType.DiskFile
// Set the format to PDF
.ExportFormatType = ExportFormatType.PortableDocFormat
// Set the destination options to DiskFileDestinationOptions object
.DestinationOptions = CrDiskFileDestinationOptions
.FormatOptions = crFormatTypeOptions
End With
Trap any errors that occur on export
Try
// Export the report
CrReport.Export()
Catch err As Exception
MessageBox.Show(err.ToString())
End Try
Thats it.... Now you are ready to create a PDF of the Report.
Here is the solution you are looking for:
http://www.c-sharpcorner.com/UploadFile/mahesh/ExportCRtoPDF10062006161918PM/ExportCRtoPDF.aspx
Here is the quote from the site:
The following steps will guide you to achieve the same:
Add crystal report (.cr) file to your ASP.NET application.
Add a report instance on the page level.
Dim report As MyReport = New MyReport
Populate reports data on Page_Init
Dim ds As DataSet = GetData()
report.SetDataSource(ds)
Export Report
report.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, False, "ExportedReport")
If you wish to format report to other formats, just change the ExportFormatType enumeration value to > your desired format.
If you wish to download the report, then you simply change the third parameter of >ExportToHttpResponse method in Step 4 to True.

an error of report document object model

I created a report using report document object model in visual studio 2008 with vb.net. But I found one error. When the user clicks export button in client side, the following error will show. But the first time is OK before the user clicks export button.
Logon failed. Details: ADO Error Code: 0x Source: Microsoft OLE DB Provider for SQL Server Description: Login failed for user 'zanhtet'. SQL State: 42000 Native Error:
This is calling report code.
Dim ReportDocument As New ReportDocument()
Dim ReportPath As String = Server.MapPath("~/ReportDocumentOM/DBlogInRDOM.rpt")
ReportDocument.Load(ReportPath)
ReportViewer.ReportSource = ReportDocument
Dim ConnectionInfo As New ConnectionInfo
ConnectionInfo.ServerName = "ZANHTET\SQLEXPRESS"
ConnectionInfo.DatabaseName = "EAS_DevTrack4UDev"
ConnectionInfo.UserID = "zanhtet"
ConnectionInfo.Password = "123456"
For Each Table As Table In ReportDocument.Database.Tables
Dim TableLogOn As TableLogOnInfo = Table.LogOnInfo
TableLogOn.ConnectionInfo = ConnectionInfo
Table.ApplyLogOnInfo(TableLogOn)
Next
How can I solve this. Please, help me.
I am not sure your code above is invoked at what place. But if you are not already doing this, then handle important events from reportviewer. Inside those event handling method, make sure you invoke this authentication code again.
Export related event should do you a luck but you may have to handle couple of others as well (like for pagination also i had similar issues).
See here for Report Viewer Events
http://msdn.microsoft.com/en-us/library/microsoft.reporting.winforms.reportviewer.reportexport.aspx

Why do we get "Path not found" error while accessing vb code from classic asp page?

Could you please give your suggestions to the below problem:
I am working on a old project which was developed using traditional ASP and VB6.0.
I have registered the dll in component services. After creating the object in first line (in the code snippet below), when trying to call Login() method, it is giving the "Path not found" warning/error and I am not able to continue executing it further.
Thanks in advance for your consideration and help...also please let me know if you need more information...
SET objSecurity = Server.CreateObject( Application("APP_CLASS") & "Security" )
SET ox = new XMLTool
userID = uCase(userID)
dataXML = ""
IF objSecurity.Login( sessXML, userID, pwd, datXML ) Then
ox.LoadXML dataXML
..........
..........
"Path not found" is usually an IO exception. Does the objSecurity.Login() method read or write any data to a file or directory that does not exist? What is happening inside the objSecurity.Login() method?
Alternately, is there another "benign" method of the objSecurity object that you can call to verify that the object lives? Something like:
Dim sTest As String = objSecurity.Version()
or
Dim sTest As String = objSecurity.Name()
or even
Dim bExists As Boolean = (objSecurity IsNot Nothing)
I know that .ToString() didn't exist in VB6, but that's the idea.
Let's narrow down the problem to either objSecurity object itself, or something inside the .Login() method.

"Both DataSource and DataSourceID are defined" error using ASP.NET GridView

"Both DataSource and DataSourceID are defined on 'grdCommunication'. Remove one definition."
I just got this error today, the code has been working until this afternoon I published the latest version to our server and it broke with that error both locally and on the server. I don't use "DataSourceID", the application reads database queries into a datatable and sets the datatable as the DataSource on the GridViews. I did a search in Visual Studio, searching the entire solution and the string "DataSourceID" does not appear in even 1 line of code in the entire solution. This is the first thing that freaked me out.
I figure it had been working yesterday, so I reverted the code to yesterday's build. The error was still there. I kept going back a build, and still the issue is there. I went back a month, I am still getting the same error. This application was working fine this morning? There has really been no code changes, and no where in the application is the DataSourceID EVER set on any of the gridviews. Has anyone ever seen anything like this at all??
How can I get that error if DataSourceID is never set... and the word "DataSourceID" is not in my solution? I just did a wingrep on the entire tree doing a case insensitive search on datasourceid.... pulled up absolutely nothing. That word is absolutely no where in the entire application.
<asp:GridView ID="grdCommunication" runat="server"
Height="130px" Width="100%"
AllowPaging="true" >
... standard grid view column setup here...
</asp:GridView>
// Code behind.. to set the datasource
DataSet dsActivity = objCompany.GetActivityDetails();
grdCommunication.DataSource = dsActivity;
grdCommunication.DataBind();
// Updated: removed some confusing notes.
Try this:
DataSet dsActivity = objCompany.GetActivityDetails();
grdCommunication.DataSource = dsActivity.Tables[0];
grdCommunication.DataBind();
Holy smoke batman. The Table name was changed causing my Datasource to be no good. But that error message doesn't make any sense in this situation. So technically tsilb's solution will work if I call the table by index instead of by name, so I'll mark his solution as correct.
After reading his post, I tried dsActivity.Tables["Activities"] instead of passing the dataset to the Datasource and the table name to the Datamember, and obviously that didn't work, but If I pass the actual index, which I don't like doing because that index might change, then it is now working. But the messed up part, was that error.. That error was completely off base as to what the problem was. saying that I defined both and to remove one, when in reality, that was not the case. and another really messed up thing, was the table name was only changed to be all upper case... But hey, "Activities" is a different key than "ACTIVITIES".
Replace this code before this grdCommunication.DataSource = dsActivity;
grdCommunication.DataBind();
grdCommunication.DataSourceID="";
tslib is right, don't do:
grdCommunication.DataSourceID = null;
or the string.Empty version. You only use the DataSourceID if you're using a SqlDataSource or ObjectDataSource control for your binding.
It's called "declarative" binding because you're using "declared" controls from on your page. Binding to controls does not require a call to the DataBind() method.
Because you're DataBinding manually (calling grd.DataBind()) you only set the DataSourrce and then call DataBind().
I ran into the same error, but a totally different problem and solution. In my case, I'm using LINQ to SQL to populate some dropdown lists, then caching the results for further page views. Everything would load fine with a clear cache, and then would error out on subsequent page views.
if (Cache["countries"] != null)
{
lbCountries.Items.Clear();
lbCountries.DataValueField = "Code";
lbCountries.DataTextField = "Name";
lbCountries.DataSource = (Cache["countries"]);
lbCountries.DataBind();}
else
{
var lstCountries = from Countries in db_read.Countries orderby Countries.Name select Countries;
lbCountries.Items.Clear();
lbCountries.DataValueField = "Code";
lbCountries.DataTextField = "Name";
lbCountries.DataSource = lstCountries.ToList();
lbCountries.DataBind();
Cache.Add("countries", lstCountries, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, 240, 0), System.Web.Caching.CacheItemPriority.High, null);
}
The issue came from:
Cache.Add("countries", lstCountries, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, 240, 0), System.Web.Caching.CacheItemPriority.High, null);
When it should have been:
Cache.Add("countries", lstCountries.ToList(), null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, 240, 0), System.Web.Caching.CacheItemPriority.High, null);
I got this error today, turns out that it had nothing to do with DataSourceID, and had everything to do with the DatasSource itself.
I had a problem in my DatasSource , and instead of getting a DatasSource related error, I got this meaningless error.
Make sure you're DatasSource is good, and this error should go away.
always bind dataset with table index to gridview...
ex. gridgrdCommunication.Table[0]; as metioned above by Tsilb
second way you intentionally write..
gridgrdCommunication.DataSourceID = String.Empty;
gridgrdCommunication.DataSource=ds;
gridgrdCommunication.DataBind();
Check you database structure.... if you are acceding your data throw a dbml file, the table structure in your database it's different of the dbml file structure
If you are using the Object Data Source and want to conditionally reload the grid in code behind you can successfully do this:
Dim datatable As DataTable = dataset.Tables(0)
Dim dataSourceID As String = gvImageFiles.DataSourceID
gvImageFiles.DataSourceID = Nothing
gvImageFiles.DataSource = datatable.DefaultView
gvImageFiles.DataBind()
gvImageFiles.DataSource = Nothing
gvImageFiles.DataSourceID = dataSourceID
You need to chose one way to bind the grid
if it is from code behind means using c# code then remove the datasourceid property from grid view from design view of grid
like this
//you have to make it like this
Please try this:
gvCustomerInvoiceList.DataSourceID = "";
gvCustomerInvoiceList.DataSource = ci_data;
gvCustomerInvoiceList.DataBind();
I got this error today. It turns out that my stored procedure did not return neither any record nor a structure. This was because I had an empty try catch without a raiserror.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Page.DataBind()
End Sub
Function GetData()
Dim dt As New DataTable
Try
dt.Columns.Add("ROOM_ID", GetType(String))
dt.Columns.Add("SCHED_ID", GetType(String))
dt.Columns.Add("TIME_START", GetType(Date))
dt.Columns.Add("TIME_END", GetType(Date))
Dim dr As DataRow = dt.NewRow
dr("ROOM_ID") = "Indocin"
dr("SCHED_ID") = "David"
dr("TIME_START") = "2018-01-03 09:00:00.000"
dr("TIME_END") = "2018-01-03 12:00:00.000"
dt.Rows.Add(dr)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Return dt
End Function
and add this to your item DataSource="<%# GetData() %>"
In my case the connection string to the database was not working. Fixing the connection string got rid of this error.

Resources