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.


Reply With Quote
