Whether to use a hashtable, datareader, array, dataset, or Datatab

G

Guest

Note, I'm using C#

I am wondering what type of control I should use for iterating through the
set of records returned by callin this method below, so that I can then do
some stuff with each record like string manipulation, or taking the data for
insertion into another table, etc..

Here's the function that returns the data as an ArrayList.

Note: You'll see plain S and B since for this post, I wanted to keep our
site name confidential for thread purposes.

public static B.Products.Product[] GetAllProductsByS(int sID)
{
IDataReader dataReader = null;
ArrayList prodList = new ArrayList();
try
{
// Initialize the database connection
Database db = DatabaseFactory.CreateDatabase();
DBCommandWrapper dbCommandWrapper =
db.GetStoredProcCommandWrapper("Pr_Ssp_ProductByS");
dbCommandWrapper.AddInParameter("@SID",
DbType.Int32, sellerStoreID);
dataReader = db.ExecuteReader(dbCommandWrapper);
while (dataReader.Read())
{
// Populate the product Var.
B.Products.Product pr = new Product();
pr.LoadCorePropertiesFromReader(dataReader);
prodList.Add(pr);
}
}
catch(Exception ex)
{
ExceptionPublisher.Publish(ex, "B");
throw;
}
finally
{
if (dataReader != null)
{
dataReader.Close();
dataReader.Dispose();
}
}
//return the arraylist as an array.
return (B.Products.Product[])
prodList.ToArray(typeof(B.Products.Product));
}


Pr_Ssp_ProductByS returns a bunch of products and all the columns for each
product from our Product table.

So I'm thinking do something like this to start off

Product[] MprodArray = B.Products.Product.GetAllProductsByS(s.SID);

So, should I use a datareader, dataset, datatable, array, or hashtable to
iterate through the results returned from my stored proc above? Since the
method returns an array, I'm not sure then what to use after this. I want to
do something like this:

for each product in the returned array
split out the productIDs out of the Product's description using regex or
something
then insert the new ProductID/Related ProductID into ProductRelationship
table
next
 
G

Guest

OK, so I guess the answer is, stick with the returned array, iterate through
it and do whatever with each record. There is no need to take the returned
array and shove it into a DataSEt or something right?
 

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

Top