SQL datasources

S

si_owen

Hi all,

Im relatively new to the .net framework and i was wandering if any one
could help me with a problem.

I have created two tables using sql. I have linked one table to a drop
down list, and require the second table's contents to be displayed in a
list box when an item is selected from the drop down list.

any help would be much appreceiated

simon.
 
R

rowe_newsgroups

On the ddl's change event build your SQL statement that will grab the
necassary rows from the table, and populate the datareader using this
SQL statement. Then use a datareader to populate the list box.
Something like:

<pseudocode>

imports System.Data.OleDb

'objConn is an open connection to your datasource

dim objDR as OleDbDataReader
dim objCmd as OleDbCommand = objConn.CreateCommand
objCmd.CommandType = CommandType.Text
objCmd.CommandText = MySQLString
objDR = objCmd.ExecuteReader

do while objDR.Read()
MyListBox.Items.Add(objDR.GetString(0))
loop

</pseudocode>

Thanks,

Seth Rowe
 
S

si_owen

hi

i already have the list box populated that all works fine!!!

but the connection between TEXT BOX and LIST BOX is where im stuck

simon
 
R

rowe_newsgroups

I think I follow, you want the textbox to have the highlighted listbox
entry right? If so:

Private Sub ListBox1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ListBox1.SelectedIndexChanged
Me.TextBox1.Text = Me.ListBox1.Text
End Sub

Thanks,

Seth Rowe
 
S

si_owen

yes thats what i meant lol

have put code in, it kind of works.

when the list box is clicked is displays the list box index no. not the
text. but i can figure that part out lol.

so thanks for your help.

however one problem is the index numbers are not matching.

my site has a drop down list box which is populated from db
connection, the drop down list when selected then populates the list
box with the correct text in relation to the drop down list box. the
list box is again attatched to a db connection. the text box now
displays data when item selected in the list box, however the item
index is higher than should be.

for example 2 rows in list box position 4 returned in text box, this is
the value from the database (where the second of the two rows for that
category (drop down list) in the list box is actually the 4th record in
the db).

any help would be much appreceited

thanks

simon
 

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