AddWithValue MySqlType.Decimal

  Uncategorised

Unfortunately, I can’t get any further. Working with vs2019 and vb. Created a cascading DropDownList (country, state, region). It works perfectly for country where I don’t have to use AddWithValue (where). With state where I have to use AddWithValue (where), I don’t get it baked. All IDs are defined as integers. The relevant code:

Protected Sub idLand_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
    DropDownBundesland.Items.Clear()
    DropDownBundesland.Items.Add(New ListItem("--Select Country--", ""))
    DropDownRegion.Items.Clear()
    DropDownRegion.Items.Add(New ListItem("--Select City--", ""))

    DropDownBundesland.AppendDataBoundItems = True
    Dim strConnString As [String] = ConfigurationManager _
               .ConnectionStrings("conString").ConnectionString
    Dim strQuery As [String] = "Select Bundesland, idBundesland, idLand from Campingplatz ORDER BY Bundesland ASC where idLand = @LandID Group BY Bundesland"
    Dim con As New MySqlConnection(strConnString)
    Dim cmd As New MySqlCommand()
    cmd.Parameters.AddWithValue("@LandID", MySqlDbType.Decimal).Value = DropDownLand.SelectedItem.Value
    cmd.CommandType = CommandType.Text
    cmd.CommandText = strQuery
    cmd.Connection = con
    Try
        con.Open()
        DropDownBundesland.DataSource = cmd.ExecuteReader()
        DropDownBundesland.DataTextField = "Bundesland"
        DropDownBundesland.DataValueField = "idBundesland"
        DropDownBundesland.DataBind()
        If DropDownBundesland.Items.Count > 1 Then
            DropDownBundesland.Enabled = True
        Else
            DropDownBundesland.Enabled = False
            DropDownRegion.Enabled = False
        End If
    Catch ex As Exception
        'Throw ex
    Finally
        con.Close()
        con.Dispose()
    End Try
End Sub

Please help!

Source: Visual Studio Questions

LEAVE A COMMENT