By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,464 Members | 1,583 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,464 IT Pros & Developers. It's quick & easy.

How get data using array or hashtable

P: n/a
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
May 16 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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>


"Mukesh" <ef*****@newsgroups.nospam> wrote in message
news:uG*************@TK2MSFTNGP02.phx.gbl...
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

May 16 '06 #2

P: n/a
Hi Mukesh,

Yes, I agree with sloan that it's not a good idea to put data in a
DataTable into an array or hashtable. Because only the data in a DataTable
or a DataSet can be updated to database using DataAdapter, which is the
simplest way of updating data. If you need to save data temporarily, please
use GetXml or WriteXml method.

Kevin Yu
Microsoft Online Community Support

================================================== ==========================
==========================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
================================================== ==========================
==========================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

May 17 '06 #3

P: n/a
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 --

Mukesh wrote:
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


Jun 8 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.