hi, iam having 2 listboxes.In one listbox i am populating products from Msacess.Then after clicking any of the product it should populate corresponding schedules in the other listbox.Below is my code Kindly reply me as soon as possible..

Dim sql As String
con = New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;Data Source=D:\Inetpub\wwwroot\WebApplication12\WRMdatabase.mdb")
sql = "select distinct scheduleid from die1 where productid =' " & ListBox1.SelectedItem.Value & " ' "
Response.Write(sql)
cmd = New OleDbCommand(sql, con)
con.Open()
reader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
' ListBox2.DataValueField = "ScheduleId"
While reader.Read
ListBox2.Items.Add(reader(0))
End While
ListBox2.Items.Clear()
ListBox2.DataSource = reader
ListBox2.DataBind()
reader.Close()

Recommended Answers

All 2 Replies

Well you are using your datareader to write your items to the listbox. then you are clearing your items. After that you are trying to assign the values from the reader to the listbox with databinding. But that is not possible because you can only read through a datareader ONCE.
And I normally use a dataset for databinding controls, so im not sure if it can work the same way with a datareader.

But anyways, i can only assume your problem is that your items are not getting populated because you didnt post your problem.

selam samsunlu,

did i understand right?

you have 2 listboxes. when you click on 1st listbox, that action will fill 2nd listbox with sql code to bring data into 2nd listbox.

yes ? no ?

thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.