How do I store a SqlParameter
in a Hashtable
? I'm trying to put P
in param
on my example below.
Hashtable param = new Hashtable();
SqlParameter P = new SqlParameter("@Picture", SqlDbType.Varbinary, b.Length, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, b);
The basic syntax to add a value to a Hashtable, using your variable names above, is:
param.Add("Picture", P);
Where "Picture" is a key you can later retrieve the item back out of the hashtable by, e.g.:
SqlParameter retrieved = (SqlParameter)param["Picture"];
That said, and as others have already commented on your question, it may be worth considering using a Dictionary over a Hashtable. A Dictionary is a typed instance of a hashtable, so you can specify the type of object you're inserting, which prevents any old junk being added to it (unless of course, you have a reason for not wanting it to be typed). I believe there's also a performance benefit in terms of boxing from having a typed Dictionary, too...