listbox and linking to database

G

Guest

Hello,
I have a form with a listbox that displays a list of records from a SQL table. When one of these is selected, another listbox is populated with data from a SQL table that is linked to the 1st table.
I'm not sure what I'm doing wrong, but when you first click on a value in listbox1, it shows a list of values in listbox2 that are linked with the PREVIOUS value in listbox1, (basically the ID of the listbox item - 1) then, if you click the listbox1 value AGAIN, it shows the correct records.
I'm using the listbox1_SelectedIndexChanged() sub.
Is this where the problem lies?
Thanks,
amber
 
R

Richard

Post your code so we can see what you're up too.
It could be anything but what you're trying to do is very simple
so when we've seen your code you'll get an answer lickety split.

At least you've identified a pattern to the bug so you probably
already have 3/4 of the answer yourself in such a simple scenario.

Post some code and we'll get it sorted.

Richard
 
G

Guest

Thanks Richard
This doesn't seem to want to work for me. I tried replying a few times last week, and creating a new post...but they never appeared
So here goes again..

Private Sub lBoxCP_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lBoxCP.SelectedIndexChange
'load cutblock lis
lBoxCB.DataSource = Nothin
Me.txtBox1.DataBindings.Clear(
Me.txtBox2.DataBindings.Clear(
Me.txtBox3.DataBindings.Clear(

OleDbDataAdapter3.SelectCommand.Parameters("ID_CUTTING_PERMIT").Value = txtCPID.Tex
DsCutBlock1.Clear(
OleDbDataAdapter3.Fill(DsCutBlock1
lBoxCB.DataSource = DsCutBlock
lBoxCB.DisplayMember = "TDT_CUT_BLOCK.STR_BLOCK_NUMBER

Me.txtBox1.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.DsCutBlock1, "TDT_CUT_BLOCK.STR_BLOCK_NUMBER")
Me.txtBox2.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.DsCutBlock1, "TDT_CUT_BLOCK.NUM_AREA_APPROVED")
Me.txtBox3.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.DsCutBlock1, "TDT_CUT_BLOCK.STR_LOCATION")

End Su
 
C

Cor

Hi Amber,

I will not say it is the only thing, but this is one of the things that is
not correct.
Me.txtBox3.DataBindings.Add(New
System.Windows.Forms.Binding("Text", Me.DsCutBlock1,
"TDT_CUT_BLOCK.STR_LOCATION"))You have to bind it to the table not to the dataset.

I asume it is a typed dataset so just the dot and than the table name,

Although probably
DsCutBlock1.tables(0) will works also if you have only one table.

I hope this helps,

Cor
 
C

Cor

Hi Amber,

You are right, I did not see the dot between the second parameters.

I did look very long and see not direct something wrong, but in your problem
you are talking about listbox1 and listbox2 and it is very hard to find what
goes wrong.

Can you tell it again but now with the right names?

Cor
 
C

Cor

I did look very long and see not direct something wrong, but in your
problem
problem = problem description (the first message)
 
G

Guest

I appreciate all your help

Having problems posting again...my most recent reply never did show up..

Okay,

My original message (with edits)
I have a form with a listbox (lBoxCP) that displays a list of records from a SQL table. When one of these is selected, another listbox (lBoxCB) is populated with data from a SQL table that is linked to the 1st table
I'm not sure what I'm doing wrong, but when you first click on a value in listbox1 (lBoxCP), it shows a list of values in listbox2 (lBoxCB) that are linked with the PREVIOUS value in listbox1 (lBoxCP), (basically the ID of the listbox item - 1) then, if you click the listbox1 value AGAIN, it shows the correct records
I'm using the lBoxCP_SelectedIndexChanged() sub

My Code
Private Sub lBoxCP_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lBoxCP.SelectedIndexChange
'load cutblock lis
lBoxCB.DataSource = Nothin
Me.txtBox1.DataBindings.Clear(
Me.txtBox2.DataBindings.Clear(
Me.txtBox3.DataBindings.Clear(

OleDbDataAdapter3.SelectCommand.Parameters("ID_CUTTING_PERMIT").Value = txtCPID.Tex
DsCutBlock1.Clear(
OleDbDataAdapter3.Fill(DsCutBlock1
lBoxCB.DataSource = DsCutBlock
lBoxCB.DisplayMember = "TDT_CUT_BLOCK.STR_BLOCK_NUMBER

Me.txtBox1.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.DsCutBlock1, "TDT_CUT_BLOCK.STR_BLOCK_NUMBER")
Me.txtBox2.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.DsCutBlock1, "TDT_CUT_BLOCK.NUM_AREA_APPROVED")
Me.txtBox3.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.DsCutBlock1, "TDT_CUT_BLOCK.STR_LOCATION")

End Su

Thanks
Ambe
 
C

Cor

Hi Amber,

Two things looks strange to me (I do not see all your code (do not send it,
because in a newsgroup that is mostly to much).

lBoxCB.DataSource = Nothing
Why do you do this on this place and not later, does that not destroy your
data (I think not but it could be the next error)
OleDbDataAdapter3.SelectCommand.Parameters("ID_CUTTING_PERMIT").Value =
txtCPID.Text

What is this Text I see it nowhere in your explanation (could misreaded it
of course).
(If you have linked it to lBoxCB it should go wrong when you set the
datasource of that to Nothing)

Maybe we are something further?

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top