473,378 Members | 1,346 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

stored procedure output to generic list, noob

I've got this really simple table with two fields

book:
name varchar(50)
phone varchar(50)

and simple stored procedure jcp1:

ALTER procedure "jcp1"
@name varchar(50) AS
SELECT phone FROM book where name = @name

from ASP.NET I have no problem using the stored procedure as a
datasource to bind rows found into a datalist control.

As a test, I wanted to try and pull the result of the stored procedure
to a list from C# .. this code isn't exactly doing that, but i I
expected it to work:

TExecuteReaderCmd<string>(sqlCmd, TGeneratephone<string>, ref
userList);
foreach (string phonex in userList)
{
if (!userList.Contains(phonex))
{
Label1.Text = phonex;
userList.Add(phonex);
}
However this code failes to retreive anything or ever execute
Label1.Text = phonex; A watch of userList shows a count of 1 in
userList when it gets to this part.

If I remove the if (!userList.Contains(phonex)) condition as follows ,
I get a "collection was modified error" at the If line - it happens on
a subsiquent second pass throught the for loop. When I do this I can
see that Label1.Text gets set to a valid phonex before crashing.

//if (!userList.Contains(phonex))
//{
Label1.Text = phonex;
userList.Add(phonex);
//}

I know the above for loop does not make sense, but I was expecting it
to work and set Label1 to the last phone returing from the stored
procedure.

Sep 15 '06 #1
1 2702

ja***@cyberpine.com wrote:
I've got this really simple table with two fields

book:
name varchar(50)
phone varchar(50)

and simple stored procedure jcp1:

ALTER procedure "jcp1"
@name varchar(50) AS
SELECT phone FROM book where name = @name

from ASP.NET I have no problem using the stored procedure as a
datasource to bind rows found into a datalist control.

As a test, I wanted to try and pull the result of the stored procedure
to a list from C# .. this code isn't exactly doing that, but i I
expected it to work:

TExecuteReaderCmd<string>(sqlCmd, TGeneratephone<string>, ref
userList);
foreach (string phonex in userList)
{
if (!userList.Contains(phonex))
{
Label1.Text = phonex;
userList.Add(phonex);
}
However this code failes to retreive anything or ever execute
Label1.Text = phonex; A watch of userList shows a count of 1 in
userList when it gets to this part.

If I remove the if (!userList.Contains(phonex)) condition as follows ,
I get a "collection was modified error" at the If line - it happens on
a subsiquent second pass throught the for loop. When I do this I can
see that Label1.Text gets set to a valid phonex before crashing.

//if (!userList.Contains(phonex))
//{
Label1.Text = phonex;
userList.Add(phonex);
//}

I know the above for loop does not make sense, but I was expecting it
to work and set Label1 to the last phone returing from the stored
procedure.
Firstly, you cannot modify the collection in a foreach loop. And since
phonex is always in the list by virtue of the foreach, it makes no
sense to check to see if it is there. Since you say that the userList
has an 1 item in it, that seems to indicate that the SQL is getting
executed since you have a result.

You might modify your loop like this:

foreach (string phonex in userList)
{
Label1.Text += phonex + "\r\n";
}

That should at least show the results inside the userList.

Chris

Sep 15 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Andrei | last post by:
Hi everyone, I am a complete noob with stored procedures. I was asked to modify the following stored procedure so that it includes the following conditions: IF InvWarehouse.DateLastSale is...
3
by: Jarrod Morrison | last post by:
Hi all Im relatively new to using stored procedures and im not sure if it is possible to do what I am trying to do so any help here is greatly appreciated. I am using the variable @MachineName...
3
by: Jarrod Morrison | last post by:
Hi All I have a stored procedure with a temporary table that with two columns in it. The first column contains 3 digit numbers and the second column some descriptive data. I was wondering what...
3
by: Michael | last post by:
This one's really got me. I have a VB.NET (version 1.1.4322) project that provides an easy way to execute stored procedures on a generic level. When I run the code on computer A (running SQL...
3
by: sumGirl | last post by:
Hi all. I have a stored procedure on my sql server that returns a simple informtation about that tim a database was backed up. I owuld like to create an HTA that operator types can look at to make...
7
by: ashtek | last post by:
Hi, I have a generic function that executes a stored procedure & returns a data table. Code: === public static DataTable ExecuteStoredProcedure(string strProc,SqlParameter paramArray) {...
7
by: Mark B | last post by:
How do I have a SiteMap based on the output of a stored procedure? (I want to pass a @LanguageCode parameter to it so it will display the top Menu in the appropriate language).
0
by: Aspersieman | last post by:
On Tue, 21 Oct 2008 20:44:24 +0200, Mike Hansen <projecktzero@yahoo.com> wrote: Hi there I hope you don't mind - I made this a new thread on the list, so others can maybe help out. ...
3
by: FrustratedNoob | last post by:
I've got a database that I've been working on for over a year and a half but I've just recently finished the back end to the point of feeling comfortable with starting on a front end. So while...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.