Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / ADO.NET / May 2005

Tip: Looking for answers? Try searching our database.

Select Statement

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
A.J - 31 May 2005 08:07 GMT
Application: When a user selects a name in the listbox complete
information(phone-no,E-mail,et­c..) 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,et­c..) 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,et­c..) 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..

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.