Reputation: 13
I am using dropdown list values Bound from data base my code
Public Function get_type() As String
'get type
If IsPostBack = False Then
da = New OleDbDataAdapter("select (type) from prod_type", con)
da.Fill(ds, "prod_type")
ddtype.DataSource = ds
ddtype.DataTextField = "type"
ddtype.DataValueField = "type"
ddtype.DataBind()
da.Dispose()
ds.Dispose()
con.Close()
End If
I call this function in page load
Upvotes: 1
Views: 4044
Reputation: 2833
Modify it like this:
Public Function get_type() As String
'get type
If IsPostBack = False Then
ds.Clear() //new
ddtype.Items.Clear() //new
da = New OleDbDataAdapter("select (type) from prod_type", con)
da.Fill(ds, "prod_type")
ddtype.DataSource = ds
ddtype.DataTextField = "type"
ddtype.DataValueField = "type"
ddtype.DataBind()
da.Dispose()
ds.Dispose()
con.Close()
End If
And if you still have duplicate entries it should be because you have duplicates in the database.
Upvotes: 0
Reputation: 3889
Edit: ignore this, it's wrong:
This is a SQL question not a asp.net or VB question. Your sql won't select unique 'types' from your prod_type table. Execute the following SQL:
select distinct(type) from prod_type
Also read the posting FAQ: https://stackoverflow.com/faq
Upvotes: 1
Reputation: 14781
There are two cases where the values would be duplicated in the DropDownList
here:
There are duplicated values in the database.
You are calling the function multiple times at the first loading of the page.
You can solve the first case by using DISTINCT in your select statement:
SELECT DISTINCT type FROM prod_type
You can solve the second by setting the value of the TableAdapter.ClearBeforeFill
property to true.
Upvotes: 0