EDIT:
Please read the comments left at the end of your question. If you won't participate like everyone else does it gets confusing and frustrating, and those who would willingly help you will just ignore your request.
Please supply some information in your post. If we dont have clear information, we are guessing wildly and making ASSumptions.
- What language are you using?
- Are you using MSSQL, MySQL, Oracle? What version?
- Linq to SQL, Linq to EF, or another ORM solution?
That stored procedure does not look like it RETURNS a value single result, but rather uses recursion and cursors to "walk" through a result. Very, Very, Very dirty.
That SP is the real problem here. I understand that you may not be able to fix it, but you may be better off by either a) making your own stored procedure, or b) calling the stored procedure the good old fashioned way with a dataAdapter or its equivalent.
As another point, you would be wise to look at the example of code that I gave to you and understand that it is going to be less prone to bugs and other problems. There are several key differences in our approaches that you should take the time to understand.
Original post:
Stored procedures typically return DataSets, not an arraylist (Those are .NET types) . Your implementation could use some cleaning up too.
Change it to something like this, forgive the syntax errs, I do VB all day.
Note: ID has both letters capitalized, and also observe how the variables are declared in each scope. You may want to choose a different pattern, but this is an example of a standard.
//retrieves a list of strings related to the itemID
public List<String> RetriveItem(int itemID)
{
// declare our return value
List _itemList = new List<String>; // int, whatever type of list
// create a data context with the using statement (so it will be cleaned up when
// the operation is completed.
using (MyDataContext _db=new MyDataContext())
{
// get the data from the stored procedure
DataSet _ds = _db.Base_RetriveItem(itemID);
// go through each row in the first table (you may have more tables to look in
foreach DataRow _dr in _ds.Tables(0)
{
// adds the first column value in the row to the return list.
_itemList.Add(Convert.ToString(_dr(0)); //convert to whatever type your list is.
}
}
return _itemList;
}
Alternately you could use the IQueryable inside the using block.
var listOfItems = from i in _db._db.Base_RetriveItem(itemID) select i;
foreach i in listOfItems
{
_itemList.Add(i); //convert to whatever type your list
}
Its kind of difficult to provide without more detail and feedback.
"is a stored procedure from the data
context the problem with the stored
procedure that drops the table
GetSubcategories"
This is really confusing. The procedure is a GET which means it GETS data, not DROPS a TABLE. Please clarify this.