Data not showing in Crystal reports - vb.net

I'm using a ConnectionString located at a Module for all of my Code in the project.
Code:
Public connString As String = "Data Source=192.168.1.11,1433;Network Library=DBMSSOCN;Initial Catalog=MY_DB;User Id=sa;Password = abc#1234
But for the Crystal Reports, I have added a project Data Source using project > add new Data Source > New Connection and used a ConnectionString.
After adding, I can see the Table and Fields. Once I add this to a Report, and browse Data through Field explorer, I don't see any Data. When I add the fields to a report, same happens. But, in the actual Table there are Rows.
What am I doing wrong here?

Related

System.Web.Services cannot be added to VB.NET project in Visual Studio

I am working on a VB.NET project in Visual Studio Community 2019, using Windows forms. I want to populate a DataGridView with data from a DataSet. But I get an error upon creating the DataSet, saying that "System.Web.Services could not be added to the project". The DataSet is then created, but I cannot chose it as a DataSource for the DataGridView. Maybe it is worthwhile to mention that my project is not intended to deal with anything online, so I wonder why should I need any Web Service stuff. How I can get rid of the error, or at least populate the DataGridView with my DataSet?
I am noticing -thanks Jon!- the following in the VB code (some 600 auto-generated lines) belonging to the DataSet:
Me.DataSetName = "DataSet1"
Me.Prefix = ""
Me.Namespace = "http://tempuri.org/DataSet1.xsd"
and further down:
Dim any1 As Global.System.Xml.Schema.XmlSchemaAny = New Global.System.Xml.Schema.XmlSchemaAny()
any1.Namespace = "http://www.w3.org/2001/XMLSchema"
I do not know how to bind the data to the grid view by hand, I was trying to use the GUI for doing it, which is not offering me the DateSet as source.
For the DataGrid view, I dragged it in from the toolbox where it can be found under "All Windows Forms"->"DataGridView".
worked now around the GUI way of creating a DataSet by
creating an xml which I can load as DataSet
<NewDataSet>
<Table0><col0>entry0row0</col0><col1>entry1row0</col1></Table0>
<Table0><col0>entry0row1</col0><col1>entry1row1</col1></Table0>
</NewDataSet>
reading in the xml by:
Imports System.xml
ds = New DataSet
Using xmlFile As XmlReader = XmlReader.Create(filename, New XmlReaderSettings())
ds.ReadXml(xmlFile)
End Using
DataGridView1.DataSource = ds.Table(0)

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.

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.

Crystal report missing parameter values when export

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

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.