Crystal Reports RecordSelectionFormula does not work - vb.net

It's my code:
CrystalReportViewer1.Zoom(75)
Dim rpt As New CrystalReport1
rpt.RecordSelectionFormula = "{members.id} ='3232'"
CrystalReportViewer1.ReportSource = rpt
CrystalReportViewer1.Refresh()
It shows all records, I don't know why

Dim CrReport As New CrystalDecisions.CrystalReports.Engine.ReportDocument
CrReport = New CrystalDecisions.CrystalReports.Engine.ReportDocument()
CrReport.Load(Application.StartupPath & "\CrystalReport1.rpt")
CrReport.SetDataSource("HERE YOUR DATASET USED IN DA DESIGN OF CRYSTALREPORT1.rpt")
CrystalReportViewer1.ReportSource = CrReport
CrReport.RecordSelectionFormula = "{members.id} ='3232'"
Your CRYSTALREPORT1.rpt must be located at \\BIN\DEBUG OF your appath and it must be almost created before. Like an object by the designer from Visual Studio... .. > ADD NEW ITEM > CR

You must create a CrystalReportDocument in Form report (desing view), and after that, the Visual Studio will display a window where you can choose a Class for CrystalReportDocument. Choose the Class related with the report.rpt, and then in the print event add this:
crystalReportDocument.Load(#"reports\report.rpt");
crystalReportDocument.RecordSelectionFormula = "{viewTable.IdTable}=1";
crystalReportDocument.PrintToPrinter(1, false, 0, 0);
viewTable is a view element in Data Base.
Many people are used to DATASET for all, but in many cases it's ridiculous.

Related

Crystal Reports 2013 Doesn't apply filter

I have a project developed in VS2008 and i'm migrating to vs2013. Everythings ok but i've noticed that all of my crystal reports doesn't apply the filters using the parameters passed.
For instance, this is the selection in the crystal report:
And i'm passing parameters this way:
Cursor = Cursors.WaitCursor
Dim CR As New ReportDocument
Dim CRParams As New ParameterFields
Dim CRParam As New ParameterField
CR.Load("infVolumenVenta2.rpt", OpenReportMethod.OpenReportByDefault)
' Creamos la conexion
Dim CRTableLogoInfos As New TableLogOnInfos
Dim CRTableLogoInfo As New TableLogOnInfo
Dim CRConnectionInfo As New ConnectionInfo
CR.SetDatabaseLogon("<user>", "<password>")
CR.ParameterFields("desde").CurrentValues.AddValue(CDate(txtDesde.Text))
CR.ParameterFields("hasta").CurrentValues.AddValue(CDate(txtHasta.Text))
CR.ParameterFields("idTienda").CurrentValues.AddValue(cmbTiendas.SelectedValue)
The Report shows:
The three fields at top are the value of the parameters i've passed before. But doesn't matter the dates i pass. Always shows the same report, the filter is not applying.
The same code and report in VS2008 works fine.
Do i have to change something to work with CR in VS2013?

How to take selected data from VB.net drop down list

I am currently practicing VB.net in Visual Studio 2013 and i have been asked to create a drop down list with data from a table which i have down and is working. What i am stuck on is how to pull the selected option from the drop down list and use that to display in a Label Web Control to show on the screen when a button is pressed to confirm the selection, Can anyone Help?
My Code on the Default.aspx.vb file
Dim dsData1 As New DataSet
dsData1 = tableData()
DDList.DataSource = dsData1
DDList.DataValueField = "code"
DDList.DataTextField = "description"
DDList.DataBind()
DDList.Items.Insert(0, New ListItem(String.Empty, String.Empty))
DDList.SelectedIndex = 0
My code in my function.vb file;
Public Shared Function tableData() As DataSet
Dim oraConnect As New OracleConnection
oraConnect.ConnectionString = ConfigurationManager.ConnectionStrings("smart_dev").ConnectionString
Dim oraCommand As New OracleCommand
oraCommand.Connection = oraConnect
oraCommand.CommandType = Data.CommandType.Text
Dim lsSQL As String = ""
lsSQL = "SELECT code, description FROM ref_code WHERE domain = 'SPECIALTY'"
oraCommand.CommandText = lsSQL
Dim da As New OracleDataAdapter(oraCommand)
Dim ds As New DataSet
da.Fill(ds)
Return ds
End Function
So basiaclly i need help with which one of these pieces of code do i edit and with what code if i open the page in a browser select an option from the dropdown and it displays on the screen.
Thank you
If i have confused anyone i apologise:)
I think you are looking for
DropDownList.SelectedItem.Text
If it's a web form the .SelectedItem.Text will only be available after the view state has been loaded, If you need to get around that you can do the following:
dim selectedText as String = page.request(DDList.UniqueId)

Error on passing multiple parameters to a Report Viewer

I'm trying to learn my way around VS 2013 using VB.net and its Report Viewer. I want to know how to pass a string to a parameter basically. And hopefully move on to other methods/procedures. Anyway I have a problem with this particular code block:
With Me.ReportViewer1.LocalReport
.ReportPath = "C:\Users\Kim\Documents\Visual Studio 2013\Projects\Tests\Tests\Report1.rdlc"
.DisplayName = "Test Report"
.DataSources.Clear()
End With
Me.ReportViewer1.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.Normal)
Dim rpT As New ReportParameter("rpTitle", "Huehuehue")
Dim rpD As New ReportParameter("rpDate", "This day")
Dim HeaderParams As ReportParameter() = {rpT, rpD}
For Each param As ReportParameter In HeaderParams
ReportViewer1.LocalReport.SetParameters(param)
Next
If I comment out Dim rpD As New ReportParameter("rpDate", "This day") and change this line Dim HeaderParams As ReportParameter() = {rpT}, the rpT part will show correctly on the report form. The result is relatively the same if I exclude rpT instead. If I use both I get a Some parameters or credentials have not been specified on my report. I've been hovering around Google for sometime now but nobody else seems to have this kind of problem.
Solved it. Apparently you had to declare it as New ReportParameter() in the SetParameters. I don't know how to use an array there. But then again I'd still need to list all the parameters, so that'd be redundant. If anybody can improve this that would be great.
ReportViewer1.LocalReport.SetParameters(New ReportParameter() {rpT, rpD})
This is how I send parameter values:
1) create a generic list of type ReportParameter
2) add your new parameters to the list with a parameter name and value and visibility
3) set the parameters for the LocalReport
Dim paramList As New Generic.List(Of ReportParameter)
paramList.Add(New ReportParameter("ReportTitle", stgReportTitle, True))
paramList.Add(New ReportParameter("ReportFooter", stgReportFooter, True))
Me.vwrReport.LocalReport.SetParameters(paramList)
Always works!

Parameters are not working passing to a crystal reports from vb.net

I am using this code to pass parameters to my crystal report, but in run time crystal report is showing text boxes to input parameters. please help me to solve this
Dim rpt As New RPT_Maintenance
rpt.SetDataSource(maintenanceDetailsTable)
rpt.SetParameterValue("datefrom", dtpDateFrom.Text)
rpt.SetParameterValue("dateto", DtpDateTo.Text)
rpt.SetParameterValue("cat", "All Vehicles")
FRM_ReportViewer.CrystelReportViewer.ReportSource = rpt
FRM_ReportViewer.ShowDialog()
FRM_ReportViewer.Dispose()
If the parameter box keep popping up, what you can do is on the page load of your crystal report viewer form, paste this:
Dim param1Fields As New ParameterFields
Dim param1Field As New ParameterField
Dim param1Range As New ParameterDiscreteValue
param1Field.ParameterFieldName = "TeamRoster"
param1Range.Value = Roster.cmbTeams.Text
param1Field.CurrentValues.Add(param1Range)
param1Fields.Add(param1Field)
CrystalReportViewer1.ParameterFieldInfo = param1Fields
You have to set Datasource to report before settings parameter like.
reportClass.SetDataSource(source);
reportClass.SetParameterValue("txtCompanyName", companyName);
viewer.SetReportSource(reportClass);

Crystal Report can't connect to database

I'm creating a program in VB.net with Visual Studio and some forms use Crystal Reports to show PDF reports, but i'm having problems with database connection. VB.net code can access the databse without problems, but when a form shows a report it asks me for username and password and if i write them it fails to connect. The application and the reports share the same database and i use the same data to connect, but Crystal Reports fails. Can you help me?
Here's a snippet that I have that works (in C#, but should give you an idea of how I did it):
CrystalReportSource CrystalReportSource1 = new CrystalReportSource();
CrystalReportViewer CrystalReportViewer1 = new CrystalReportViewer();
CrystalReportViewer1.ReportSource = CrystalReportSource1;
CrystalReportViewer1.EnableParameterPrompt = false;
CrystalReportSource1.Report.FileName = "Report3.rpt";
CrystalReportSource1.EnableCaching = false;
CrystalReportSource1.ReportDocument.SetParameterValue(0, ponumber);
CrystalReportSource1.ReportDocument.SetParameterValue(1, receiptno);
TableLogOnInfo logOnInfo = new TableLogOnInfo();
logOnInfo.ConnectionInfo.ServerName = ConfigurationManager.AppSettings["WarehouseReportServerName"];
logOnInfo.ConnectionInfo.DatabaseName = ConfigurationManager.AppSettings["WarehouseReportDatabaseName"];
logOnInfo.ConnectionInfo.UserID = ConfigurationManager.AppSettings["WarehouseReportUserID"];
logOnInfo.ConnectionInfo.Password = ConfigurationManager.AppSettings["WarehouseReportPassword"];
TableLogOnInfos infos = new TableLogOnInfos();
infos.Add(logOnInfo);
CrystalReportViewer1.LogOnInfo = infos;
maindiv.Controls.Add(CrystalReportSource1);
maindiv.Controls.Add(CrystalReportViewer1);
CrystalReportViewer1.DataBind();
Although you said that you are using the designers, I 'll post some code that is working for me, maybe it will help you:
Dim cryRpt As New ReportDocument
Dim strReportPath As String = 'The Path of the rpt file
cryRpt.Load(strReportPath)
cryRpt.SetDataSource(Me.crData) 'crData is a datatable with data for the report
crvReport.ReportSource = cryRpt 'crvReport is the CrystalReportViewer in my form
Check if all fields exist in the data when you set in "SetDataSource"