473,320 Members | 1,990 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,320 software developers and data experts.

Getting multiple SELECTED values from stored procedure into an array?

Amy
Hello,

I've been struggling to learn C#.NET for a while now. I've made some
progress, but I'm easily stumped. :(

What's stumping me today is this:
I've got a stored procedure (SQL) that returns one row from a table,
and up to 3 rows from another table. I want to read the values of the
three rows into an array, but I can't figure out how to do it. The
code I have compiles, but I suspect it's not quite what I'm looking
for. Basically, how do I iterate through the contactUIDs that are
being returned from the sp?

Thanks in advance,

amy

code:

if (drProject.Read())
{
p = new Project();
p.ProjName = drProject["projName"].ToString();
p.ProjDescrip = drProject["description"].ToString();
p.ProjRequestedDeadline = drProject["requestedDeadline"].ToString();
p.ProjBasecampURL = drProject["basecampURL"].ToString();
p.ProjStatus = drProject["Status"].ToString();
p.ProjStatusID = Int32.Parse(drProject["statusID"].ToString());
p.ProjFreq = drProject["freqtype"].ToString();
p.ProjFreqID = Int32.Parse(drProject["freqID"].ToString());
p.ProjPriority = drProject["priority"].ToString();
p.ProjPriorityID = Int32.Parse(drProject["priorityID"].ToString());
p.ProjDateProposed = drProject["dateProposed"].ToString();

for (int i=0; i<=3; i++)
{
p.ProjContactUIDs[i] =
Int32.Parse(drProject["contactUID"].ToString());
}
}
Nov 17 '05 #1
4 2610
Assuming your stored procedure returns multiple resultsets, try this code:

Add drProject.NextResult() before the for loop. This will move the reader to
the next result.

And add drProject.Read() inside the for loop (before assigning to the
array).

"Amy" <am*******@mccombs.utexas.edu> wrote in message
news:v6********************************@4ax.com...
Hello,

I've been struggling to learn C#.NET for a while now. I've made some
progress, but I'm easily stumped. :(

What's stumping me today is this:
I've got a stored procedure (SQL) that returns one row from a table,
and up to 3 rows from another table. I want to read the values of the
three rows into an array, but I can't figure out how to do it. The
code I have compiles, but I suspect it's not quite what I'm looking
for. Basically, how do I iterate through the contactUIDs that are
being returned from the sp?

Thanks in advance,

amy

code:

if (drProject.Read())
{
p = new Project();
p.ProjName = drProject["projName"].ToString();
p.ProjDescrip = drProject["description"].ToString();
p.ProjRequestedDeadline = drProject["requestedDeadline"].ToString();
p.ProjBasecampURL = drProject["basecampURL"].ToString();
p.ProjStatus = drProject["Status"].ToString();
p.ProjStatusID = Int32.Parse(drProject["statusID"].ToString());
p.ProjFreq = drProject["freqtype"].ToString();
p.ProjFreqID = Int32.Parse(drProject["freqID"].ToString());
p.ProjPriority = drProject["priority"].ToString();
p.ProjPriorityID = Int32.Parse(drProject["priorityID"].ToString());
p.ProjDateProposed = drProject["dateProposed"].ToString();

for (int i=0; i<=3; i++)
{
p.ProjContactUIDs[i] =
Int32.Parse(drProject["contactUID"].ToString());
}
}
Nov 17 '05 #2
Amy
I don't *think* it returns multiple resultsets (forgive me, my
background is adabas/NATURAL, I'm still learning the 'modern' lingo) -
it returns one project record (er, row), with multiple ContactUIDs. So
is what you're saying that I should add the drProject.Read() inside
the for loop?

Thanks again,

Amy

On Fri, 14 Oct 2005 23:24:52 +0530, "Siva M"
<sh******@online.excite.com> wrote:
Assuming your stored procedure returns multiple resultsets, try this code:

Add drProject.NextResult() before the for loop. This will move the reader to
the next result.

And add drProject.Read() inside the for loop (before assigning to the
array).

"Amy" <am*******@mccombs.utexas.edu> wrote in message
news:v6********************************@4ax.com.. .
Hello,

I've been struggling to learn C#.NET for a while now. I've made some
progress, but I'm easily stumped. :(

What's stumping me today is this:
I've got a stored procedure (SQL) that returns one row from a table,
and up to 3 rows from another table. I want to read the values of the
three rows into an array, but I can't figure out how to do it. The
code I have compiles, but I suspect it's not quite what I'm looking
for. Basically, how do I iterate through the contactUIDs that are
being returned from the sp?

Thanks in advance,

amy

code:

if (drProject.Read())
{
p = new Project();
p.ProjName = drProject["projName"].ToString();
p.ProjDescrip = drProject["description"].ToString();
p.ProjRequestedDeadline = drProject["requestedDeadline"].ToString();
p.ProjBasecampURL = drProject["basecampURL"].ToString();
p.ProjStatus = drProject["Status"].ToString();
p.ProjStatusID = Int32.Parse(drProject["statusID"].ToString());
p.ProjFreq = drProject["freqtype"].ToString();
p.ProjFreqID = Int32.Parse(drProject["freqID"].ToString());
p.ProjPriority = drProject["priority"].ToString();
p.ProjPriorityID = Int32.Parse(drProject["priorityID"].ToString());
p.ProjDateProposed = drProject["dateProposed"].ToString();

for (int i=0; i<=3; i++)
{
p.ProjContactUIDs[i] =
Int32.Parse(drProject["contactUID"].ToString());
}
}

Nov 17 '05 #3
Are the project details (except contact ID) same for all records? If so, add
drProject.Read() inside the for loop.

However, note that if the number of contact IDs (that is, number of records
returned) are less than three then Read() will throw exception after reading
available records (because the loop count is hardcoded). This can be fixed
by adding "if (!drProject.Read()) break;" instead of just drProject.Read();

Hope I have not added any confusion..
"Amy" <am*******@mccombs.utexas.edu> wrote in message
news:uj********************************@4ax.com...
I don't *think* it returns multiple resultsets (forgive me, my
background is adabas/NATURAL, I'm still learning the 'modern' lingo) -
it returns one project record (er, row), with multiple ContactUIDs. So
is what you're saying that I should add the drProject.Read() inside
the for loop?

Thanks again,

Amy

On Fri, 14 Oct 2005 23:24:52 +0530, "Siva M"
<sh******@online.excite.com> wrote:
Assuming your stored procedure returns multiple resultsets, try this code:

Add drProject.NextResult() before the for loop. This will move the reader
to
the next result.

And add drProject.Read() inside the for loop (before assigning to the
array).

"Amy" <am*******@mccombs.utexas.edu> wrote in message
news:v6********************************@4ax.com.. .
Hello,

I've been struggling to learn C#.NET for a while now. I've made some
progress, but I'm easily stumped. :(

What's stumping me today is this:
I've got a stored procedure (SQL) that returns one row from a table,
and up to 3 rows from another table. I want to read the values of the
three rows into an array, but I can't figure out how to do it. The
code I have compiles, but I suspect it's not quite what I'm looking
for. Basically, how do I iterate through the contactUIDs that are
being returned from the sp?

Thanks in advance,

amy

code:

if (drProject.Read())
{
p = new Project();
p.ProjName = drProject["projName"].ToString();
p.ProjDescrip = drProject["description"].ToString();
p.ProjRequestedDeadline = drProject["requestedDeadline"].ToString();
p.ProjBasecampURL = drProject["basecampURL"].ToString();
p.ProjStatus = drProject["Status"].ToString();
p.ProjStatusID = Int32.Parse(drProject["statusID"].ToString());
p.ProjFreq = drProject["freqtype"].ToString();
p.ProjFreqID = Int32.Parse(drProject["freqID"].ToString());
p.ProjPriority = drProject["priority"].ToString();
p.ProjPriorityID = Int32.Parse(drProject["priorityID"].ToString());
p.ProjDateProposed = drProject["dateProposed"].ToString();

for (int i=0; i<=3; i++)
{
p.ProjContactUIDs[i] =
Int32.Parse(drProject["contactUID"].ToString());
}
}

Nov 17 '05 #4
Amy
When I tried, this, I get a System.StackOverflowException.

On Fri, 14 Oct 2005 23:24:52 +0530, "Siva M"
<sh******@online.excite.com> wrote:
Assuming your stored procedure returns multiple resultsets, try this code:

Add drProject.NextResult() before the for loop. This will move the reader to
the next result.

And add drProject.Read() inside the for loop (before assigning to the
array).

"Amy" <am*******@mccombs.utexas.edu> wrote in message
news:v6********************************@4ax.com.. .
Hello,

I've been struggling to learn C#.NET for a while now. I've made some
progress, but I'm easily stumped. :(

What's stumping me today is this:
I've got a stored procedure (SQL) that returns one row from a table,
and up to 3 rows from another table. I want to read the values of the
three rows into an array, but I can't figure out how to do it. The
code I have compiles, but I suspect it's not quite what I'm looking
for. Basically, how do I iterate through the contactUIDs that are
being returned from the sp?

Thanks in advance,

amy

code:

if (drProject.Read())
{
p = new Project();
p.ProjName = drProject["projName"].ToString();
p.ProjDescrip = drProject["description"].ToString();
p.ProjRequestedDeadline = drProject["requestedDeadline"].ToString();
p.ProjBasecampURL = drProject["basecampURL"].ToString();
p.ProjStatus = drProject["Status"].ToString();
p.ProjStatusID = Int32.Parse(drProject["statusID"].ToString());
p.ProjFreq = drProject["freqtype"].ToString();
p.ProjFreqID = Int32.Parse(drProject["freqID"].ToString());
p.ProjPriority = drProject["priority"].ToString();
p.ProjPriorityID = Int32.Parse(drProject["priorityID"].ToString());
p.ProjDateProposed = drProject["dateProposed"].ToString();

for (int i=0; i<=3; i++)
{
p.ProjContactUIDs[i] =
Int32.Parse(drProject["contactUID"].ToString());
}
}

Nov 17 '05 #5

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

Similar topics

3
by: Vipul Pathak | last post by:
Hello Friends ! I have the Following Code, that Executes a Stored Procedure and Attempt to read a Returned Integer Value from the StoredProc. But It gives Error ... ADODB.Command (0x800A0BB9)...
4
by: Richard G | last post by:
I'm a database guy, so go easy on me here. :) How can I get the rowcount of the affected rows of a SQL statement from a stored procedure call? I know that "set nocount on" does not return the...
3
by: Suresh | last post by:
Hi All I am writing Import\Export routine in DB2 using stored procedure and front end as JAVA. For this I have two option 1) Writing five different stored procedure returning one cursor...
0
by: WB | last post by:
Hi, I have a ListBox in a Windows form. This ListBox contains a list of products for a user to choose. It's bound to a DataSet like this: listBox1.DataSource = dsProducts.Tables;...
2
by: jed | last post by:
I have created a stored procedure in SQLExpress management.I need to retrieve a numeric value that the stored procedure creates and use it in a C# application.Please help thanks. USE GO /******...
4
by: gamaz | last post by:
Hi, I am trying to work on a stored procedure that will work with multiple database. I have a prototype of multiple databases. Those are named as the following: ts2_aldkm_app, ts2_aldkp_app,...
1
by: balurbabu | last post by:
I am asp.net 2.0 c#.net, I have a list box,listLocation which allows the user to select mulitple selections. These are stored in a database as comma separated values like bangalore,chennai,delhi...
2
by: E11esar | last post by:
Hi there, I am working on creating an Oracle stored procedure and am running into all kinds of problems. Below is my first attempt at this and will hopefully highlight what it is I am trying to...
2
by: ezhar | last post by:
int ctr = dataGridView1.CurrentCellAddress.Y; string str = dataGridView1.Value.ToString(); Form1 frm = (Form1)Application.OpenForms; frm.textBox1.Text = str; I...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.