JTR
JTR

Reputation: 333

VB.NET : input string was not in a correct format

anyone... can you guys help me? when i'm running the application i get error message

Input string was not in a correct format.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.FormatException: Input string was not in a correct format.

this is the source error:

Line 77: dt = brKendaraan.GetList(txtKeyword.Text.ToString, Convert.ToInt32(ddlMerk.SelectedValue), Convert.ToInt32(ddlPerusahaan.SelectedValue), ddlStatus.SelectedValue.ToString)

and this is my code in aspx.vb

Dim dt As New DataTable
    Dim brKendaraan As New BL.KendaraanBr
    dt = brKendaraan.GetList(txtKeyword.Text.ToString, Convert.ToInt32(ddlMerk.SelectedValue), Convert.ToInt32(ddlPerusahaan.SelectedValue), ddlStatus.SelectedValue.ToString)

    If dt.Rows.Count > 0 Then
        Dim report As New ReportDocument()
        report.Load(Server.MapPath("~/Reports/Kendaraan.rpt"))
        report.SetDataSource(dt)
        CRVKendaraan.ReportSource = report
    End If

please help me

Upvotes: 0

Views: 6138

Answers (3)

NeverHopeless
NeverHopeless

Reputation: 11233

My guess is that you are using Convert.ToInt32() function, so please make sure you are providing a correct value which is convertible to integer. The error:

Input string was not in a correct format.

means that the parameters is not in a correct format as it should be. Print the SelectedValue of your drop downs to dig more on this issue. Perhaps you have problem in data binding.

Hope it helps!

Upvotes: 1

JTR
JTR

Reputation: 333

finally, i tried to add this above my code, and it's work!

Dim sKeyword As String = Nothing
    Dim iMerkKendaraan As Nullable(Of Integer) = Nothing
    Dim iPerusahaan As Nullable(Of Integer) = Nothing
    Dim bStatus As Nullable(Of Boolean) = Nothing

    If (Not String.IsNullOrEmpty(ddlMerk.SelectedValue)) Then iMerkKendaraan = Convert.ToInt32(ddlMerk.SelectedValue)
    If (Not String.IsNullOrEmpty(ddlPerusahaan.SelectedValue)) Then iPerusahaan = Convert.ToInt32(ddlPerusahaan.SelectedValue)
    If (Not String.IsNullOrEmpty(txtKeyword.Text)) Then sKeyword = txtKeyword.Text
    If (Not String.IsNullOrEmpty(ddlStatus.SelectedValue)) Then bStatus = ddlStatus.SelectedValue

Thanks for your help guys! :D

Upvotes: 0

John Louie Dela Cruz
John Louie Dela Cruz

Reputation: 669

Add open and close parenthesis () in the end of ToString

dt = brKendaraan.GetList(txtKeyword.Text.ToString(), Convert.ToInt32(ddlMerk.SelectedValue), Convert.ToInt32(ddlPerusahaan.SelectedValue), ddlStatus.SelectedValue.ToString())

Upvotes: 0

Related Questions