From: dba123 on
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

--
dba123
From: "David Browne" davidbaxterbrowne no potted on


"dba123" <dba123(a)discussions.microsoft.com> wrote in message
news:D7CB4ED8-5A87-4ADB-825F-B5BB073D63D2(a)microsoft.com...
> 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,
.. . ...
>Since the
> method returns an array, I'm not sure then what to use after this. I want
> to
> do something like this:
>

C# Programmer's Reference

Using foreach with Arrays
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfusingforeachwitharrays.asp

David