S
shookim
I am trying to populate a combobox and then fire an indexchanged event
handler. My combobox populates fine, the problem is when it gets to
the datasource object (cmbClient.DataSource = ds), it immediately goes
to the event handler (SelectedIndexChanged), which later causes an
error. This is my code:
Private Sub PopulateClient()
Dim sqlConn As SqlConnection = New
SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Try
Dim ds As New DataSet("ds")
Dim objDataAdapter As SqlDataAdapter = New SqlDataAdapter
Dim cmd As SqlCommand = New SqlCommand("SELECT ClientName
FROM tblClients", sqlConn)
sqlConn.Open()
objDataAdapter.SelectCommand = cmd
objDataAdapter.Fill(ds, "Clients")
'Set up the Combobox bindings
cmbClient.DataSource = ds
cmbClient.SelectedIndex = 0
cmbClient.DisplayMember = "Clients.ClientName"
Catch ex As Exception
'Error Handler
lblError.Visible = True
lblError.Text = Err.Description()
Finally
'Close the connection.
sqlConn.Close()
End Try
End Sub
Private Sub cmbClient_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
cmbClient.SelectedIndexChanged
Call PopulateEntity(cmbEntity.SelectedValue)
End Sub
Any suggestions??
handler. My combobox populates fine, the problem is when it gets to
the datasource object (cmbClient.DataSource = ds), it immediately goes
to the event handler (SelectedIndexChanged), which later causes an
error. This is my code:
Private Sub PopulateClient()
Dim sqlConn As SqlConnection = New
SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Try
Dim ds As New DataSet("ds")
Dim objDataAdapter As SqlDataAdapter = New SqlDataAdapter
Dim cmd As SqlCommand = New SqlCommand("SELECT ClientName
FROM tblClients", sqlConn)
sqlConn.Open()
objDataAdapter.SelectCommand = cmd
objDataAdapter.Fill(ds, "Clients")
'Set up the Combobox bindings
cmbClient.DataSource = ds
cmbClient.SelectedIndex = 0
cmbClient.DisplayMember = "Clients.ClientName"
Catch ex As Exception
'Error Handler
lblError.Visible = True
lblError.Text = Err.Description()
Finally
'Close the connection.
sqlConn.Close()
End Try
End Sub
Private Sub cmbClient_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
cmbClient.SelectedIndexChanged
Call PopulateEntity(cmbEntity.SelectedValue)
End Sub
Any suggestions??