KC GSR
October 10th, 2005, 12:40 PM
Hey everyone,
I am working on my first VB .Net applications and I am having problems passing three parameters to a report. The problem is 2 of the parameters are date fields and the last one is an integer field. If I make all of the parameters the same type (such as all dates, or all integers) then it works just fine. But when the parameter field types are different, then I get an error message that says "Input string was not in a correct format."
I have tried to manually specify the parameter field types but when I do that I get something along the lines of "the parameter field type is not the same as the current field type."
What I am doing is passing a datatable to a subroutine that is supposed to open the report. The datatable contains each parameter field name as well as the values entered by the user. When I created the datatable, I set both column types to "string" so I don't know if that is part of my problem or not. Anyway, here is my code if any of you might be able to point me in the right direction.
Like I said though, if I change the parameter types on my report to all dates or all integers, the report displays just fine.
Public Sub Show_Report(ByVal paramTable As DataTable)
Dim i As Integer
Dim myTable As CrystalDecisions.CrystalReports.Engine.Table
Dim myLogin As New CrystalDecisions.Shared.TableLogOnInfo
Dim myFields As New CrystalDecisions.Shared.ParameterFields
Dim thisField As CrystalDecisions.Shared.ParameterField
Dim myValue As New CrystalDecisions.Shared.ParameterDiscreteValue
rptFile = cmbRptList.SelectedValue
crDoc = New CrystalDecisions.CrystalReports.Engine.ReportDocument
crDoc.Load(rptFile)
For i = 0 To paramTable.Rows.Count - 1
thisField = New CrystalDecisions.Shared.ParameterField
thisField.ParameterFieldName = paramTable.Rows(i).Item(0)
myValue.Value = paramTable.Rows(i).Item(1)
thisField.CurrentValues.Add(myValue)
myFields.Add(thisField)
Next
Try
CrystalReportViewer1.ParameterFieldInfo = myFields
Catch ex As Exception
MsgBox(ex)
End Try
For Each myTable In crDoc.Database.Tables
myLogin = myTable.LogOnInfo
myLogin.ConnectionInfo.Password = "password"
myLogin.ConnectionInfo.UserID = "userid"
myTable.ApplyLogOnInfo(myLogin)
Next
CrystalReportViewer1.ReportSource = rptFile
End Sub
I am working on my first VB .Net applications and I am having problems passing three parameters to a report. The problem is 2 of the parameters are date fields and the last one is an integer field. If I make all of the parameters the same type (such as all dates, or all integers) then it works just fine. But when the parameter field types are different, then I get an error message that says "Input string was not in a correct format."
I have tried to manually specify the parameter field types but when I do that I get something along the lines of "the parameter field type is not the same as the current field type."
What I am doing is passing a datatable to a subroutine that is supposed to open the report. The datatable contains each parameter field name as well as the values entered by the user. When I created the datatable, I set both column types to "string" so I don't know if that is part of my problem or not. Anyway, here is my code if any of you might be able to point me in the right direction.
Like I said though, if I change the parameter types on my report to all dates or all integers, the report displays just fine.
Public Sub Show_Report(ByVal paramTable As DataTable)
Dim i As Integer
Dim myTable As CrystalDecisions.CrystalReports.Engine.Table
Dim myLogin As New CrystalDecisions.Shared.TableLogOnInfo
Dim myFields As New CrystalDecisions.Shared.ParameterFields
Dim thisField As CrystalDecisions.Shared.ParameterField
Dim myValue As New CrystalDecisions.Shared.ParameterDiscreteValue
rptFile = cmbRptList.SelectedValue
crDoc = New CrystalDecisions.CrystalReports.Engine.ReportDocument
crDoc.Load(rptFile)
For i = 0 To paramTable.Rows.Count - 1
thisField = New CrystalDecisions.Shared.ParameterField
thisField.ParameterFieldName = paramTable.Rows(i).Item(0)
myValue.Value = paramTable.Rows(i).Item(1)
thisField.CurrentValues.Add(myValue)
myFields.Add(thisField)
Next
Try
CrystalReportViewer1.ParameterFieldInfo = myFields
Catch ex As Exception
MsgBox(ex)
End Try
For Each myTable In crDoc.Database.Tables
myLogin = myTable.LogOnInfo
myLogin.ConnectionInfo.Password = "password"
myLogin.ConnectionInfo.UserID = "userid"
myTable.ApplyLogOnInfo(myLogin)
Next
CrystalReportViewer1.ReportSource = rptFile
End Sub