Hashtable to Data List?

S

Sparky Arbuckle

Hello all! I am trying to get information from a HashTable to display
in a DataList using a SQL statement. Is this possible? When the visitor
'adds item to cart' they are redirected to
ShoppingCart.aspx?add=ITEMID. The HashTable simply stores The ITEMID,
Quantity, and an option for ADD / REMOVE.

I have a database table, tblItemInfo, that has the description,
prices, images, etc... of each individual ITEMID. How would I go about
correllating the Data List and displaying the information from the
HashTable?

If you need code samples please let me know and I will supply more. For
now:

<!----- THIS IS AS FAR AS I'VE GOTTEN ----->

IF htCart.Count = 0 THEN
lblMessage.text = "<tr><td align='center' colspan='3'>Cart is
empty</td></tr>"
ELSE
FOR EACH myItem as DictionaryEntry in htCart

Dim objConn as new
OLEDBConnection(ConfigurationSettings.AppSettings("StrConnection"))
Dim strSQL as string = "SELECT ITEMID, PRICE, Description, ImageDir
FROM tblItemInfo WHERE ITEMID = '" & myItem.key & "';"

Dim objDataReader as OLEDBDataReader

objConn.Open()

Dim objCommand as new OLEDBCommand(strSQL,objConn)
Music.DataSource =
objCommand.ExecuteReader(CommandBehavior.CloseConnection)
dlINFO.DataBind()
dlINFO.RepeatColumns = 1

lblMessage.text += _
"<table>" & _
"<tr>" & _
"<td>" & myItem.Key & "</td>" & _
"<td>" & myItem.Value & "</td>" & _
"<td><a href='?Delete=" & myItem.Key & "'>Remove</a>" &
_
"<a href='?Add=" & myItem.Key & "'>Add </a></td>" &
_
"</tr>" & _
"</table>"
NEXT
END IF

<!----- THIS IS AS FAR AS I'VE GOTTEN ----->
 
S

Scott Allen

Hi Sparky:

It looks as if what you want to display is not the contents of the
Hashtable, but the records you can get back by querying the database
with keys from the hashtable.

A good idea would be to try and pull back all the records at one time.
You could do this with the IN keyword, for example:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_ia-iz_8him.asp

You'll also want to move to a parameratized query, as string
concatenation can open security holes.
 

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

Members online

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
KetoBurn
Top