I want to search clients that got to shop between two dates.
The code I use seems alright and it doesn't return any error but the CR returns everything - It does not use the date search function. The CR I use is tested with a simple program that open CR and works fine.
database is ms access and code is in visual studio 2005
The second issue I have is that despite i use the connection info part it still ask me for a code
PS. sorry for my bad formatting , i am new in stackoverflow and i find it hard to make a post
thank you!
-Agisilaos
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Public Class Form1
Dim crConnectionInfo As New ConnectionInfo()
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim cryRpt As New ReportDocument
cryRpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument
cryRpt.Load("C:\Users\agis\Documents\Visual Studio 2005\Projects\new_contracts _of_month\new_contracts _of_month\CrystalReport2.rpt", CrystalDecisions.Shared.OpenReportMethod.OpenReportByTempCopy)
With crConnectionInfo
.ServerName = "C:\Users\agis\Desktop\Insurance database\Insurancemanager.mdb"
.UserID = "Admin"
.Password = "kos"
.DatabaseName = "insurancemanager"
End With
'first parameter
Dim crParameterFieldDefinitions As ParameterFieldDefinitions
Dim crParameterFieldDefinition As ParameterFieldDefinition
Dim crParameterValues As New ParameterValues
Dim crParameterDiscreteValue As New ParameterDiscreteValue
crParameterDiscreteValue.Value = Convert.ToDateTime(TextBox1.Text)
crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields
crParameterFieldDefinition = crParameterFieldDefinitions.Item("startdate")
crParameterValues = crParameterFieldDefinition.CurrentValues
crParameterValues.Add(crParameterDiscreteValue)
crParameterValues.Clear()
' second parameter :
Dim crParameterFieldDefinitions2 As ParameterFieldDefinitions
Dim crParameterFieldDefinition2 As ParameterFieldDefinition
Dim crParameterValues2 As New ParameterValues
Dim crParameterDiscreteValue2 As New ParameterDiscreteValue
crParameterDiscreteValue2.Value = Convert.ToDateTime(TextBox2.Text)
TextBox3.Text += " " + crParameterDiscreteValue2.Value
crParameterFieldDefinitions2 = cryRpt.DataDefinition.ParameterFields
crParameterFieldDefinition2 = crParameterFieldDefinitions2.Item("enddate")
crParameterValues2 = crParameterFieldDefinition2.CurrentValues
crParameterValues2.Clear()
crParameterValues2.Add(crParameterDiscreteValue2)
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
crParameterFieldDefinition2.ApplyCurrentValues(crParameterValues2)
CrystalReportViewer1.ReportSource = cryRpt
CrystalReportViewer1.Refresh()
End Sub
End Class
Don’t understand what exactly your problem is but I assume that you want to pass parameter to report and filter report data on those parameters also want to set run-time connection settings of crystal report.
First create parameter field in your report (right click on parameter fields and click on add in crystal designer)
Now go to “crystal report->report->select expert” menu in visual studio crystal report designer and set data filter condition using these parameter fields.
For passing parameter to report use parameter name and value like this
cryRpt.ParameterFields("parametername").CurrentValues.AddValue(objVal)
cryRpt.ParameterFields("fromdatetime").CurrentValues.AddValue(Now)
you don’t have to set any server name for ms access database better way is create dsn for your database file and use that dsn in your report so your report will never ask for database file unless data file is missing you can even create dsn programmatically at run time if want that let us know
if you wat to set sql like server database password and login at runtime use
repDoc.DataSourceConnections(0).SetLogon("usrID","psw")
repDoc.DataSourceConnections(0).IntegratedSecurity = False
Related
I'm developing a solution to get data from SharePoint Online List, but when I try to retrieve and execute the query, do a error. The error is.
System.Net.WebException: 'The remote server returned an error: (403) Forbidden.'
Im using 4 textboxs (URL, User, Password, NameList) and a Datagridview.
Using context As ClientContext = New ClientContext(TextBox1.Text.Trim())
context.AuthenticationMode = ClientAuthenticationMode.[Default]
context.Credentials = New NetworkCredential(TextBoxName.Text.Trim(), TextBoxPassword.Text.Trim(), "https://example.sharepoint.com/sites/SPSite/")
Dim webObj As Web = context.Web
Dim listObj As List = webObj.Lists.GetByTitle(TextBoxLista.Text.Trim())
Dim cqObj As CamlQuery = CamlQuery.CreateAllItemsQuery(100)
Dim collObj As ListItemCollection = listObj.GetItems(cqObj)
context.Load(collObj)
context.ExecuteQuery() 'Line whit error
End Using
Could you help me to know the reason for the error and how to solve it?
Thank you in advance.
Regards.
This is the code whit the solution.
Thank you.
Imports Microsoft.SharePoint.Client
Imports Microsoft.SharePoint
Imports System.Security
Imports System.Net
Public Class Form4
Dim siteUrl As String = "https://namedomain.sharepoint.com/sites/TaskSP/"
'namedomain is the name of the site domain, TaskSP is the name site.
Dim context As New ClientContext(siteUrl)
Dim web As Web
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
Dim userNameSP As String = TextBox1.Text
'Textbox1.text is the mail account to access site.
Dim password As String = TextBox2.Text
'Textbox2.text is the password of your mail account to access site.
Dim secureString As SecureString = New NetworkCredential("", password).SecurePassword
Dim cred = New SharePointOnlineCredentials(userNameSP, secureString)
Dim clientContext As New ClientContext(siteUrl)
clientContext.Credentials = cred
Dim web As Web = clientContext.Web
Dim oWebsite As Web = clientContext.Web
Dim collList As ListCollection = oWebsite.Lists
Dim oList As List = collList.GetByTitle("TestList")
'TestList is the name of the list you want to query
clientContext.Load(oList)
clientContext.ExecuteQuery()
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub
End Class
I hope this is useful if you need it.
Regards.
As the question title suggests, my vb.net project that uses Crystal Reports 9 and a password restricted MS-Access 97 database.
When loading reports, the Load method calls cReport.VerifyDatabase() which has previously been working fine without a password, but since adding one, it isn't working, and gives me the following error
Log on failed.
at CrystalDecisions.CrystalReports.Engine.ReportDocument.VerifyDatabase()
What do I need to add/change to this code for it to log on successfully?
Private Sub frmReportViewer_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
setFormSizes(Me, con)
Me.Location = New Point((Screen.PrimaryScreen.WorkingArea.Width / 2) - (Me.Width / 2), 10)
Me.Text = "Report Viewer - (" & Replace(cReport.FileName, "rassdk://", "") & ")"
cReport.VerifyDatabase()
cReport.Refresh()
crViewer.ReportSource = cReport
crViewer.ToolPanelView = CrystalDecisions.Windows.Forms.ToolPanelViewType.None
crViewer.Zoom(87)
Catch ex As Exception
errorLog(ex)
End Try
End Sub
EDIT
The data can be viewed when opening the report file in Crystal Reports itself, but this is because I can manually enter the password.
According to this documentation : 1.4.4.1.2
Use this method to log database with your report before verify the database :
Private Function SubreportLogon_RD(ByVal TestReport As ReportDocument) As ReportDocument
Dim dataSourceConnections As DataSourceConnections = TestReport.DataSourceConnections
Dim connectInfo As IConnectionInfo = dataSourceConnections(0)
connectInfo.SetConnection("ServerName", "DatabaseName", "UserName", "Password")
Dim TestSubreport As ReportDocument = TestReport.Subreports("Subreport1")
Dim subreportDataSourceConnections As DataSourceConnections = TestSubreport.DataSourceConnections
Dim connectInfo As IConnectionInfo = subreportDataSourceConnections(0)
connectInfo.SetLogon("UserName", "Password")
End Function
As per MSDN
Dim logOnInfo As New TableLogOnInfo()
Dim i As Integer
For i = 0 To cReport.Database.Tables.Count - 1
logOnInfo.ConnectionInfo.DatabaseName = "Database_Name"
logOnInfo.ConnectionInfo.Password = "Password"
cReport.Database.Tables.Item(i).ApplyLogOnInfo(logOnInfo)
Next i
I am developing a project using VB2008 and Crystal Reports 11.5.
I have added new crystal report to the project and it is working fine with the folowing code.
Dim ds As New DataSet
mysqlDataAdapter1 = New MySqlDataAdapter("SELECT * from client_reg where c_qid='" & TextBox2.Text & "'", SQLConnection)
mysqlDataAdapter1.Fill(ds, "client_reg")
ds.WriteXml(CurDir() + "\work_order.xml", XmlWriteMode.WriteSchema)
Dim cryRpt As New work_order '// this is my rpt file in project
rpt_view.CrystalReportViewer1.ReportSource = cryRpt '// rpt_view is the form with empty report viewer
rpt_view.CrystalReportViewer1.Refresh()
rpt_view.CrystalReportViewer1.RefreshReport()
rpt_view.Show()
Now I want to change the XML file location dynamically as follows;
ds.WriteXml("C:\new\bin\work_order.xml", XmlWriteMode.WriteSchema)
How can I change the RPT datasource to new path???
Thank you,
Sameera
Try Something like :
Create Property called:
Public Property ds() As DataSet
Get
Return ViewState("ds")
End Get
Set(ByVal value As DataSet)
ViewState("ds") = value
End Set
End Property
Then set report datasource to be the dataset
Public Sub BindReport(ByVal Id As String)
ds.WriteXml("C:\new\bin\work_order.xml", XmlWriteMode.WriteSchema)
cryRpt.SetDataSource(ds)
rpt_view.ReportSource = cryRpt
If rblFormat.SelectedValue = 1 Then
cryRpt.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, True, "ExportedReport")
Else
cryRpt.ExportToHttpResponse(ExportFormatType.WordForWindows, Response, True, "ExportedReport")
End If
Call This method at the button event
I am using Visual Basic in Visual Studio 2012 with Crystal Reports for Visual Studio.
I have a parameter in a Crystal Report that can accept multiple values (for instance: Regions). How do I pass multiple values to that single parameter from vb.net? The values would be coming from selections from a ListBox.
Sorry if this is answered elsewhere. I have tried many searches all over internet with no luck.
Thanks in advance!
Bob
As asked for, here is code from where I select a single value from ComboBox. The Parameter in the Crystal Report is BuyDate. I just am not sure how to make it for multiple values. If you need more details, just let me know.
Dim crParameterFieldDefinitions As ParameterFieldDefinitions
Dim crParameterFieldDefinition As ParameterFieldDefinition
Dim crParameterValues As New ParameterValues
Dim crParameterDiscreteValue As New ParameterDiscreteValue
Dim SSBuy = New CrystalDecisions.CrystalReports.Engine.ReportDocument()
Dim Filepath = "\\filepath\Report By Buy Date.rpt"
SSBuy.Load(Filepath)
crParameterDiscreteValue.Value = ComboBox1.SelectedItem
crParameterFieldDefinitions = SSBuy.DataDefinition.ParameterFields
crParameterFieldDefinition = crParameterFieldDefinitions.Item("BuyDate")
crParameterValues = crParameterFieldDefinition.CurrentValues
crParameterValues.Clear()
crParameterValues.Add(crParameterDiscreteValue)
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
SSBuyForm.CrystalReportViewer1.ReportSource = SSBuy
SSBuyForm.Refresh()
SSBuyForm.Show()
I was able to find the answer on the SAP website. Here is the link to the article, for anyone else who may need it.
Pass Multiple Values to a Parameter
Also, here is the actual code I used, which runs a report based on PO#'s selected from a ListBox.
Dim crParameterFieldDefinitions As ParameterFieldDefinitions
Dim crParameterFieldDefinition As ParameterFieldDefinition
Dim crParameterValues As New ParameterValues
Dim crParameterDiscreteValue As New ParameterDiscreteValue
Dim SSPO = New CrystalDecisions.CrystalReports.Engine.ReportDocument()
Dim Filepath = "\\Filepath\Report Download By PO #.rpt"
SSPO.Load(Filepath)
crParameterFieldDefinitions = SSPO.DataDefinition.ParameterFields
crParameterFieldDefinition = crParameterFieldDefinitions("PO#")
crParameterValues = crParameterFieldDefinition.CurrentValues
Dim Count As Integer = POList1.SelectedItems.Count
For i = 0 To Count - 1
If i > 0 Then
crParameterDiscreteValue = Nothing
End If
crParameterDiscreteValue = New ParameterDiscreteValue()
crParameterDiscreteValue.Value = POList1.SelectedItems(i)
crParameterValues.Add(crParameterDiscreteValue)
Next
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
SSPoForm.CrystalReportViewer1.ReportSource = SSPO
SSPoForm.Refresh()
SSPoForm.Show()
I created a report by using crystal report. I used ado.net connection for this. I created a dataset and joined report.
In coding veiw
Dim Rpt As New ReportDocument
Dim ClientAdp As New ClientTableAdapters.ClientsTableAdapter
Dim ClientDt As New Client.ClientsDataTable
ClientAdp.Connection = New SqlConnection(ConfigurationManager.ConnectionStrings("CurrentConnection").ConnectionString)
ClientAdp.Fill(ClientDt)
Rpt.Load(Server.MapPath(ADONET_REPORT_FILE))
Rpt.SetDataSource(CType(ClientDt, DataTable))
Rpt.SetDatabaseLogon("123", "123")
ReportViewer.ReportSource = Rpt
This is OK in first load time. And when I clicks print button in report view, the report view ask logon information. How can I fit this
I think you need to set the TableLogOnInfo for each table within your report not just the Report.
Dim logOnInfo As TableLogOnInfo
For Each tbCurrent As CrystalDecisions.CrystalReports.Engine.Table In Rpt.Database.Tables
logOnInfo = tbCurrent.LogOnInfo
logOnInfo.ConnectionInfo.DatabaseName = "MyDatabaseName"
logOnInfo.ConnectionInfo.UserID = "UserId"
logOnInfo.ConnectionInfo.Password = "secretpassword"
logOnInfo.ConnectionInfo.ServerName = "SQLServer"
logOnInfo.ConnectionInfo.Type = ConnectionInfoType.SQL
tbCurrent.ApplyLogOnInfo(logOnInfo)
Next
I have a blog post here which details this in full (It's written in C# but the same principles apply for VB.NET)