How get data using array or hashtable

  • Thread starter Thread starter Mukesh
  • Start date Start date
M

Mukesh

Hi
I am creating a web application in which I am using datagrid. In this
application I am creating a shopping cart sort of application, I have
primery keys of selected items in a array i want to take full details
of the them in a single datareader. How can i do this passing a single
hashtable or array in database and retriving the desired data in a
single datatable. plz give me any idea or link
Thx
Mukesh Agarwal
 
You can't pass an array or hashtable into a database.

You can however, pass a 0:N item list thru xml to the database.

Check my article:
http://www.sqlservercentral.com/columnists/sholliday/
"Zero to N"

You can keep your values in a Array or Hashtable....

Right before you want to query the database, convert it to a strongly typed
dataset, and push the DataSet.GetXml() into the stored procedure.

The xml of a StronglyType dataset would look something like this.


<ProductsListDS>
<Product>
<ProductID>123</ProductID>
</Product>
<Product>
<ProductID>567</ProductID>
</Product>
<Product>
<ProductID>897</ProductID>
</Product>
</ProductsListDS>
 
Not sure of your question.

Are you looking to fetch multiple records from a database, using a list
of "selected product IDs" ?

All you need is a simple Select query

"SELECT A, B, C FROM [MYPRODUCTTABLE] WHERE MYPRODUCTKEY IN(
PRODUCTKEY1, PRODUCTKEY 2, ... )"

Construct the query by looping through your selected products
array/hashtable (using a for-each)

WARNING: make sure you protect agains SQL injection attacks.

g'luck.
-- a --
 

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

Back
Top