suicehockey44
asked on
VB.NET clear data binded listbox items doesn't work
I am at a loss. The button_click below is supposed to clear the items of a listbox, which is bound to a dataset, and then rebind based on a new set of parameters. I really thought the:
lbbuyer.Datasource = Nothing statement would have worked.
The result with the button push is simply that the new items simply get added on to the old ones.
Please Help
lbbuyer.Datasource = Nothing statement would have worked.
The result with the button push is simply that the new items simply get added on to the old ones.
Please Help
Private Sub btnGetBuyers_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetBuyers.Click
lbBuyer.DataSource = Nothing
lbBuyer.Items.Clear()
OpenCon()
Dim sqlcmd As New SqlCommand
Dim strState As String = GetSelections(lbState)
Dim strFund As String = GetSelections(lbFund)
With sqlcmd
.Connection = conString
.CommandType = CommandType.StoredProcedure
.CommandText = "SP_GETBUYERS"
.CommandTimeout = 1000
.Parameters.Add("@State", SqlDbType.Char, 3)
.Parameters.Add("@Fund", SqlDbType.Char, 20)
.Parameters("@State").Direction = ParameterDirection.Input
.Parameters("@Fund").Direction = ParameterDirection.Input
.Parameters("@State").Value = strState
.Parameters("@Fund").Value = strFund
.ExecuteNonQuery()
End With
Dim daBuyer As New SqlDataAdapter("SELECT DISTINCT CounterpartyName FROM tblInvBuyers", conString)
daBuyer.Fill(dsInvoice, "Buyer")
lbBuyer.DataSource = dsInvoice.Tables("Buyer")
With lbBuyer
.DataSource = dsInvoice.Tables("Buyer")
.DisplayMember = "CounterpartyName"
End With
CloseCon()
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
listbox.Clear