Select Statement Error!!!

  • Thread starter Thread starter A.J
  • Start date Start date
A

A.J

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..
 
AJ,

It is a different approach than we normal see, however I cannot see anything
wrong, than this obvious one.
str = "select * from contacts where id = '" &
rdr( "arr(lstbox1.selectedindex )") & "'"
arr(lstbox1.selectedindex) & "'"

It is better to use command parameters by the way.

For SQL server to protecct against hackers for others just because it is
nicer and as well usable with stored procedures..

http://msdn.microsoft.com/library/d...rfsystemdataoledboledbparameterclasstopic.asp

I hope this helps,

Cor
 
A.J said:
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..

If your ID field is numeric, remove the single quotes (') around the id field value and it should work.

str = "select * from contacts where id = " & rdr( "arr(lstbox1.selectedindex )")
 
Back
Top