Application: When a user selects a name in the listbox complete
information(phone-no,E-mail,etc..) regarding the person should be
displayed.
Problem: I have populated the list-box with names using datareader.The
database comprise of id with respect to each name.Now since the id's
are unique thats why while populating the listbox i am storing the id's
in an array.
dim arr(10) as integer
ex. arr(i) = rdr("id").
Now when the user selects a name the query i am writing is
str = "select * from contacts where id = '" &
rdr( "arr(lstbox1.selectedindex )") & "'"
Now i am getting error in the where clause.
Please Help..
Piyush Thakuria - 31 May 2005 09:07 GMT
Hi,
There are few things which are there. Firstly you can avaoid the use of
array here. The list box had two propertires. One is valus and other is test.
You can bind the Employees id to the list box value. And use the query as:
str = "select * from contacts where id =" & lstbox1.selectedindex.value
If you want to try with array, just try removing single quotes from both
side as your id seems to be integer and you are using it as string.
for e.g. use id =" & rdr( "arr(lstbox1.selectedindex )")
instead of id = '" & rdr( "arr(lstbox1.selectedindex )") & "'"
Please let me know if it solves your problem.
thanks and Regards,
Piyush Thakuria
Technical Lead
> Application: When a user selects a name in the listbox complete
> information(phone-no,E-mail,etc..) regarding the person should be
[quoted text clipped - 13 lines]
>
> Please Help..
A.J - 31 May 2005 12:34 GMT
You talked about the two properties of ListBox ie. value and test.
1. listbox1.selectedindex.value automatically populates or we have to
populate it.
2. tell me about the property "test". What is its usage?
Once the problem is solved i will definitely inform you
Cor Ligthert - 31 May 2005 10:49 GMT
AJ,
Will you please not multipost, I have answered you in another newsgroup the
error is very simple.
Cor
Chris Mayers - 31 May 2005 14:15 GMT
You can't do what you're trying to do with the DataReader. It only contains
the current record that it has read from the record set.
anyway, rdr( "arr(lstbox1.selectedindex )") is trying to return the field
called "arr(lstbox1.selectedindex)" from the current record in the reader
which should either return an error, or null, not sure which...
You would be better off creating a little object to display in your listbox
that has 2 properties (Name and Id) and set the DisplayMember property of
the listbox to the 'Name' property of your object.
Or you could use your current technique, but write something like:
str = "select * from contacts where id = '" & arr(listbox1.SelectedIndex) &
"'";
Application: When a user selects a name in the listbox complete
information(phone-no,E-mail,etc..) regarding the person should be
displayed.
Problem: I have populated the list-box with names using datareader.The
database comprise of id with respect to each name.Now since the id's
are unique thats why while populating the listbox i am storing the id's
in an array.
dim arr(10) as integer
ex. arr(i) = rdr("id").
Now when the user selects a name the query i am writing is
str = "select * from contacts where id = '" &
rdr( "arr(lstbox1.selectedindex )") & "'"
Now i am getting error in the where clause.
Please Help..