Results 1 to 2 of 2

Thread: Combo Box SelectedIndexChangedEvent

  1. #1
    New Member
    Join Date
    Aug 12
    Posts
    5

    Combo Box SelectedIndexChangedEvent

    Dear fellow I have one combo box on from and its bind with data source in the combo box selectedIndexChangedEvent i write some code.

    Private Sub FRM_LOGIN_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    OpenConnect()
    cboDistributor(cboDistributorLocations)
    'cboDistributorLocations.SelectedIndex = -1
    End Sub


    Private Sub cboDistributorLocations_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboDistributorLocations.SelectedIndexChanged


    If cboDistributorLocations.SelectedIndex > 0 Then
    Try
    Dim cmd As New SqlCommand
    If (Cnn.State.Equals(ConnectionState.Closed)) Then
    Cnn.Open()
    End If
    cmd.CommandText = "usp_Search_DistributorLocation_ByDistributorLocationID"
    cmd.CommandType = CommandType.StoredProcedure
    cmd.Parameters.Add("@DistributorLocationID", SqlDbType.Int).Value = cboDistributorLocations.SelectedValue
    cmd.Connection = Cnn
    Dr = cmd.ExecuteReader
    If Dr.Read = True Then
    Dist_ID = Dr(1)
    End If
    Dr.Close()
    Catch ex As Exception
    MsgBox(ex.Message)
    End Try
    End If

    End Sub
    Problem is this code can not be executed when selected index is =0 and when i change selected index >=0 than it generate errors.
    "Failed to convert Parameters value from a DataRowView to int 32 ". but combo box on 0 index has a value of integer.

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,459

    Re: Combo Box SelectedIndexChangedEvent

    cmd.Parameters.Add("@DistributorLocationID", SqlDbType.Int).Value = cboDistributorLocations.SelectedValue
    That can't be right!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •