473,789 Members | 2,703 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:

TExecuteReaderC md<string>(sqlC md, TGeneratephone< string>, ref
userList);
foreach (string phonex in userList)
{
if (!userList.Cont ains(phonex))
{
Label1.Text = phonex;
userList.Add(ph onex);
}
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.Cont ains(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.Cont ains(phonex))
//{
Label1.Text = phonex;
userList.Add(ph onex);
//}

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 2718

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:

TExecuteReaderC md<string>(sqlC md, TGeneratephone< string>, ref
userList);
foreach (string phonex in userList)
{
if (!userList.Cont ains(phonex))
{
Label1.Text = phonex;
userList.Add(ph onex);
}
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.Cont ains(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.Cont ains(phonex))
//{
Label1.Text = phonex;
userList.Add(ph onex);
//}

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
3981
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 null then use InvWarehouse.DateLastStockMove else
3
6587
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 which is obviously the local machine name mainly in this procedure. What is loop through from the first character of the variable to the last and use this data in a select statement. I have included the code below for what I have tried so far but I...
3
2878
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 the easiest way is to output the first column. So far i was thinking along the lines of using a loop and combining the first column together into a single variable to output of the stored procedure but am unsure if this is the best way to do it ?...
3
18610
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 Server 2000 version 08.00.0194) the code works great. However, computer B (running SQL Server 2000 version 08.00.0534) bombs when I try to execute the sproc saying 'Could not find stored procedure 'spmw_ReadByPage'. My thought process went as...
3
3176
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 sure that the backups finished, can someone help me do this? The stored procedure in called sp_lastback and the output looks like this: database days since backup timestamp of backup dbase1 0 2004-10-14 00:41:21.000
7
8564
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) { SqlCommand command = new SqlCommand(strProc, connection); command.CommandType = CommandType.StoredProcedure;
7
1602
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
1431
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. Although I use Linux quite often, I'm afraid MS SQL (with python) from
3
2828
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 I've been able to pick up a great deal just stumbling through on my own with the several apress books I've gotten a hold of I've figured out a great deal and have some half decent forms for data entry but for the life of me I can't figure out how to get...
0
9666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10410
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10200
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9984
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9020
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5418
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.