Crystal report missing parameter values when export - vb.net

When I ran my crystal report, I run into an error where its shows missing parameter values
Below is my code
_crAdviceRpt.Load("C:\Users\whatever\AD_AdviceTemplate.rpt")
Dim ds As ADDataset = New ADDataset
Dim dt As DataTable = ds.Tables.Add("ADDatatable")
dt.Columns.Add(New DataColumn("strLinesList", Type.GetType("System.String")))
Dim dr As DataRow
dr = dt.NewRow
dr("strLinesList") = strLine
dt.Rows.Add(dr)
_crAdviceRpt.SetDataSource(ds.Tables(1))
CrDiskFileDestinationOptions.DiskFileName = "location.pdf"
CrExportOptions = _crAdviceRpt.ExportOptions
With CrExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.PortableDocFormat
.DestinationOptions = CrDiskFileDestinationOptions
.FormatOptions = CrFormatTypeOptions
End With
_crAdviceRpt.Export()
If Not _crAdviceRpt Is Nothing Then
_crAdviceRpt.Close()
_crAdviceRpt.Dispose()
_crAdviceRpt = Nothing
End If
In my dataset, it does like this:
ADDDataset.xsd-> ADDatatable -> strLinesList
strLinesList is my column over here
In crystal report designer, I drag the strLinesList over to my .rpt
I'm not sure what is wrong but I'm pretty sure that something is missing in my code, so anyhere is appreciated

The Solution for this is to reorder the Crystal Parameters to match the Query Prompts
1) Open the problem report in Crystal Designer
2) Right click the Parameters section and select reorder parameters
3) Set the Parameter order to match that of the Prompts in the query
4) save the report and retest
The Verify Database command on the Database menu checks the alias pointers stored in a report file to verify that the database files expected are located in the indicated directories. If the databases are not found in the specified location, the program notifies you of the discrepancies.
Using the Verify Database process
When you choose Verify Database from the Database menu, the program checks the active databases and reports. If it detects changes, the report must be adapted to prevent errors. The program displays the Map Fields dialog box when it detects either of these types of changes to the database:
- The name of a database field that is used in the report has changed
- The database has been upsized from a PC data source to an SQL data source.
Crystal Reports automatically adapts the report (and does not display the Map Fields dialog box) if it detects any of these changes:
- Fields have been added to the database
- Fields that are not used in the report have been deleted from the database
- Field positions have changed in the database
- Data types have changed for fields in the database.
Using the Verify on Every Print process
Verify on Every Print triggers the Verify Database command every time you print your report.
- If there is a check mark beside Verify on Every Print, the option is active. It triggers Verify Database every time you print.
- If there is no check mark beside it, the option is inactive. The option is inactive by default.
Link

Related

Passing data from a Datagrid to Report Viewer

I'm relatively new to form programming in Visual Basic and need some help.
I've successful got what I want from my database into a datagrid but need this in a report viewer.
dgvReport.DataSource = dsReport
Dim ds As DataTable = New DataTable("GenerateReport")
Dim ReportDataSource = New ReportDataSource("GenerateReport", ds)
rvReport.LocalReport.DataSources.Clear()
rvReport.LocalReport.DataSources.Add(ReportDataSource)
rvReport.LocalReport.ReportEmbeddedResource = "Test.Report1.rdlc"
rvReport.RefreshReport()
Where 'dsReport' is the name of the dataset I'm using.
'Generate Report' is the table name within the dataset.
"Test.report1.rdlc" is the path of the report file.
I've searched and found this code, but the error I get says that the the program cannot find the file. I was unaware that there's a file saved which you then copy the data from into the report viewer.
I don't know if this is right, what I'm doing. Any help is much appreciated.

Identifying exact location of data entry issues when bulk copying or importing from excel to access

One of the requirements of a project that I have is to allow users to import or copy and paste in bulk a few hundred rows from excel to access. However, there is a reasonable chance due to human error that there will be some data validation issues between the imported data and the table structure/referential integrity rules. I would like to be able to identify exactly the field/s and record/s where these issues are occuring so that I can point them out to the user for correction.
As such the standard error essages like 'you cannot add or change a record because a related record is required in...' or 'data type mismatch in criteria or expression' are not descriptive enough to the exact location of the problem so even if I catch them I can't really give a better descriptor anyway
I am debating importing to a completely free text temporary table, then looping an insert to move one row at a time from the temp table to the properly validated table and using dbfailonerror to catch issues on individual records that need correction (the user needs to correct them I can't do this through code)
My question is whether this is a reasonable approach, is there a better/easier way, or a way to get a more specific error from access rather than using a loop?
Thanks
There are 2 ways to do this. I'm not sure what method you are using to do the import but if is as simple as copying rows from the excel sheet to the table Access will generate a Paste_errors table that will show the rows it couldn't import. The wizard will do the same thing but I think its prone to crashing.
The way I typically do it is actually have the end user use an excel template with a VBA backend that does the uploading. You can check each value conditionally and give a better descriptive alert and/or shuttle any defective rows to a temporary table for you to review.
You can do this the opposite way and do the import through Access VBA but that would be more coding since you would have to create an Excel object in code, open the sheet, etc.
I setup a Quickbooks export of a accounts receivable table by creating a User DSN on the local machine pointing to the Access file, opening an ADO recordset and looping through the rows one column at a time applying logic to each row.
Quickbooks would ask for an existing file to dump the data into so I made that a template file on the network. It sounds like your users may have to enter directly into the spreadsheet so you would have to distribute the template but the results are the same.
Example of Looping through the sheet and validating rows
Create a DSN file to the database and store it on a shared drive, this way you don't have to hardcode the string and if you need to change something, you only have to change the dsn file instead of redistributing templates.
Public Sub Upload
'Declare the main recordset that the records will be uploaded to.
Dim rstUpload as New Adodb.Recordset
'Declare a utility recordset object that you can reuse to check referential tables
Dim rstCheck as New Adodb.recordset
'Declare a utility command object that you can reuse to check referential tables
Dim SQLCommand as New Adodb.Command
'Declare the connection object to the database
Dim dataConn as New Adodb.Connection
'A tracking flag if you find something in a row that won't upload
Dim CannotUpload as Boolean
'Open the connection to the access database
dataConn.Open "\\Server\Share\Mydatabase.dsn" 'Your dsn file'
Set SQLCommand.ActiveConnection = DataConn
rst.Open "yourTable", dataConn, adOpenDynamic, adLockBatchOptimistic
For i = 1 to 100 ' Rows
*You may want to do a pass through the rows so you can get an accurate count, usually just loop through the rows until a column that must have data is blank. If your users are skipping rows that is going to be a problem.
rstUpload.AddNew
'Set the tracking Flag to False indicating you can upload this row, this will be changed if any field cannot be validated
CannotUpload = False
'First Column/Field: 'Non critical field, any value will do
rstUpload("Field1").Value = Range(i,1).Value '
'Second Column/Field has a referential integrity constraints
'Run a query against the table that has the values you are trying to validate.
SQLCommand.CommandText = "Select IDField From YourTable where ID = " & Range(i,2).Value
Set rstCheck = SQLCommand.Execute
'Check if any records were returned, if none than the value you are checking is invalid
If rstCheck.RecordCount > 0 Then 'we matched the value in the cell
rstUpload ("Field2").Value = Range(i,2).Value
else
'Design a flagging method, maybe highlight the cell in question
CannotUpload = True
End if
....continue through your columns in the same fashion, reusing the SQLCommand Object and the Utility recordset when you need to lookup something in another table
'After last column
If CannotUpload = False Then
'Nothing triggered the flag so this row is good to go
rstUpload.Update
Else
'Cannot Upload is true and this row won't be uploaded
rstUpload.Cancel
End If
Next i
dataconn.Close
set dataConn = Nothing
set rstUpload = Nothing
set rstCheck = Nothing
set SQLCommand = Nothing

Crystal Reports - Changing Table Locations No working

I have an application developed in VB6 which I am migrating to .Net Framework 4.0. There is a report that works correctly in the original application but the migrated application does not work on the original application. As a special feature, this report changed at runtime attribute "location" in two tables (actually they are seen) used to generate the SQL with which the report is fed, but when "shooting" the reporete the changes in tables with the attribute "location" are not reflected, that I can display using the "SQL Server Profiler" tool:
objReportDocument.Database.Tables(0).Location = "NameReferenceTable""
My point is this: When the report was build, they used 5 database tables of the data base: Table1, Table2, Table3, Table4 and Table5. Later, in de data base, the tables Table1 and Table2 were deleted. The idea is that en run time a store procedure constructed Table1 and Table2 like temporary tables with the original name more any id string; this new data base tables must be used when the report are rise.
When you walk over the Tables array of the report (ReportDocument.DataBase.Tables(n)), for each table you can see two key properties: Name and Location. I understand than Location propertie indicates to Crystal Reports with which tables should work to build the reorts, this is true?
I have not much experience with Crystal Reports, I investigated two weeks why this error is generated without an answer ... I hope you can help me a bit, I really appreciate it.
regards,
Fabian.
I will provide a method that I use for our Crystal Reports objects in my application. This is just used to set the login information for the report (our reports use built-in security), but if I am understanding your problem correctly, then you should be able to add/modify this method to set the Location as well.
The properties used in the method below are:
Me.ConnectionInfo is type CrystalDecisions.Shared.ConnectionInfo
Me.LogOnInfo is type CrystalDecisions.Shared.TableLogOnInfo
Me.Report is type CrystalDecisions.CrystalReports.Engine.ReportDocument
Also, g_strDb, g_strServer, and g_strMirror are some Strings whose value is irrelevant.
One thing I have found working with Crystal Reports in .NET, is that you need to set properties at the Table level, as you can see in the method below. Hopefully this helps you with your issue.
''' <summary>
''' Apply the database connection info to all tables recursively.
''' </summary>
''' <param name="crxRpt">The report document (or subreport) to apply connection info.</param>
Private Sub SetConnectionInfo(ByVal crxRpt As ReportDocument)
Dim reportObject As ReportObject
Dim subReportObject As SubreportObject
Dim section As Section
Dim t As Table
For Each t In crxRpt.Database.Tables
' if the DatabaseName in the report is <special db name>,
' we need to make sure to set the DatabaseName to the environment
' that the user is currently connected to in order to be able to
' pull the correct information for the report
If t.LogOnInfo.ConnectionInfo.DatabaseName = "<special db name>" Then
Me.ConnectionInfo.DatabaseName = g_strDb
Else
Me.ConnectionInfo.DatabaseName = t.LogOnInfo.ConnectionInfo.DatabaseName
End If
' only ApplyLogOnInfo for tables that are being pulled from the SQL
' server, this avoids problems that arise with reports that are
' created using field definition files
If t.LogOnInfo.ConnectionInfo.ServerName = g_strServer OrElse t.LogOnInfo.ConnectionInfo.ServerName = g_strMirror Then
t.ApplyLogOnInfo(Me.LogOnInfo)
End If
Next t
For Each section In crxRpt.ReportDefinition.Sections
For Each reportObject In section.ReportObjects
If reportObject.Kind = ReportObjectKind.SubreportObject Then
subReportObject = CType(reportObject, CrystalDecisions.CrystalReports.Engine.SubreportObject)
SetConnectionInfo(subReportObject.OpenSubreport(subReportObject.SubreportName))
End If
Next reportObject
Next section
End Sub
The above method is called from a setup method:
''' <summary>
''' Initialize the database connection info.
''' </summary>
Public Sub SetUpReport()
Me.LogOnInfo = New TableLogOnInfo
Me.ConnectionInfo.UserID = conUID
Me.ConnectionInfo.Password = conPWD
Me.ConnectionInfo.ServerName = g_strServer
Me.ConnectionInfo.DatabaseName = g_strDb
Me.SetConnectionInfo(Me.Report)
End Sub
And SetUpReport() is called any time we need to display/print the report.
Well, finally find the solution...
In my conection to BD use ODBC, the associate user to this conection no had a schema associate in the BD, then when the store procedure created the temporaly tables there are creates below the shchema bdo, but when crystal reports rise the report (used my ODBC with the associate user) no found the temporaly tables. So I associated a scheemma to the user used in my ODBC.
My original reports are old, then I had to open each one in VS2012, overwrite the report to update the format and test in Main Report Preview.

Unable to add tables to Crystal Reports

Background:
I have an old report in which I am trying to add a table and a field. The report works perfectly fine in my web application. (Crystal reports ver. 11.5.9.1076)
After adding a table I get the error:
System.Runtime.InteropServices.COMException: Failed to open connection
This happens whether I add a table, command, or stored procedure to the report. (Connecting to Oracle database)
Things I've tried:
Add table (crashes), remove table (works again)
Click the "Verify database" button in the Database menu
Set database location and update the newly added table
Previewing the report seems to work
As for how I'm providing the data:
Create and load ReportDocument (VB.net)
Populate DataSet
Call SetDataSource method with DataSet as param
ExportToHttpResponse as PortableDocFormat
Here is what we had to do in order to make this work in our crystal reports: after loading the report, we loop through each of the DataSourceConnections in the report and update the connection information.
For Each oConnection As IConnectionInfo In oReport.DataSourceConnections
If fUseIntegratedSecurity Then
oConnection.SetConnection(sServerName, sDatabaseName, True)
Else
oConnection.IntegratedSecurity = False
oConnection.SetConnection(sServerName, sDatabaseName, sUserLogon, sUserPassword)
End If
Next
The actual connection details are provided elsewhere in our app, so I am just showing placeholders in the code above.

Retrieving records from SQL Server CE [is anybody on this planet can solve this issue??]

I have included database in my project(at root).
The connection string
Data Source=|DataDirectory|\TSM_DB.sdf;Password=xxx;Persist Security Info=True;Max Database Size=512
TSM_DB.sdf properties:
Build Action = Content
Copy to Output Directory = Copy if newer
Dataset properties:
Build Action = None
Copy to Output Directory = Do Not Copy
My problem:
When I try to insert data into the database it gets inserted to the database present in Debug folder and not in the database which is included in the project...
And that’s why (obviously) my select statement does not find any record in the database (according to my connection string)...
I think the query (code) is perfectly fine, but some sort of settings need be done.
How do I solve this issue?
EDIT :
Example Select Code (working : when connection string path is Absolute)
Try
Dim cnt_temp
Dim SQLquery As String
Dim myConString As String = My.Settings.TSM_DBConnectionString
con.ConnectionString = myConString
SQLquery = "SELECT * FROM tbl_outward"
Dim DA As SqlCeDataAdapter, Ds As New DataSet, Dtb As New System.Data.DataTable
DA = New SqlCeDataAdapter(SQLquery, con)
DA.Fill(Ds)
Dtb = Ds.Tables(0)
cnt_temp = Dtb.Rows.Count
MsgBox(cnt_temp)
con.Close()
Catch ex As Exception
MsgBox("Error..!", MsgBoxStyle.Exclamation)
End Try
When I try to insert data into the database it gets inserted to the database present in Debug folder and not in the database which is included in the project...
Which is exactly what you told it to do, and is what you want. The database in your project folder is part of the source code. When you test or debug your code, the data changed is part of your test or temporary debug output, not your source code.
When you test your code, would you want the test overwriting your source code? I hope not, that would destroy your source; and when you deploy your project you don't usually deploy your source code. The same is true of your data; the data in your project is part of your application and is not the end-user data. When you install your application your source data gets installed to DataDirectory, which is part of your application and is not user data; the user may not even be able to write to it.
When you uninstall or update your application, DataDirectory gets uninstalled or updated. You don't want to do that to your user's data; would you like it if every time you updated Microsoft Word it deleted every Word file on your drive? That's what would happen if Word stored user data in its equivalent of DataDirectory.
DataDirectory is only for your app's private use. If a user needs this data you should copy it to a user-writable place that won't get deleted, like Environment.SpecialFolder.ApplicationData.
Further explanations at this answer.