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

datareader return with one result instead of two

Hi,

I am using Datareader and stored procedure in C# ADO.NET.
When I am running the stored procedure in the SQL Query Analyzer and
recieve two rows (as I hace expected)
col1 col2
0 1
0 2
4 2

but when I run it via code the datareader returns with only one result.

Hope someone overcome this and could help
-------------------------------------------------------------------------------------------------------------------------
The Stored procedure

CREATE PROCEDURE FetchData @columnlist char(255), @recordlist
char(255), @tablename char(255)

AS
BEGIN
SET NOCOUNT ON

DECLARE @SQL varchar(8000)

SET @SQL =
' SELECT ' + @columnlist + ' FROM ' + @tablename + 'WHERE rd_id IN
(' + @recordlist + ')'

EXEC(@SQL)
END
GO

-------------------------------------------------------------------------------------------------------------------------
The code
string sqlCommand = "FetchData";

DBCommandWrapper dbCommandWrapper =
db.GetStoredProcCommandWrapper(sqlCommand);
dbCommandWrapper.AddInParameter("@columnlist", DbType.String,
sColumn);
dbCommandWrapper.AddInParameter("@recordlist", DbType.String, records);
dbCommandWrapper.AddInParameter("@tablename", DbType.String, table);
dataReader = db.ExecuteReader(dbCommandWrapper);
do {
while (dataReader.Read()) {
try{
o = dataReader["rms_v1_max"]; }catch{}
try{
o = dataReader["rms_v1_min"]; }catch{}

}
} while (dataReader.NextResult());
*****The innner while runs only one time because the NextResult return
false
Thanks in advance
Oren

Nov 20 '05 #1
2 3379
Well, the loop calling NextResult should only run once. You are only
returning one result set. From what I can tell, your code looks correct
(and from what you say, acting correct). Since you are returning one result
set, your call to NextResult runs once, and cycles through the rows in that
result set.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<or****@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
Hi,

I am using Datareader and stored procedure in C# ADO.NET.
When I am running the stored procedure in the SQL Query Analyzer and
recieve two rows (as I hace expected)
col1 col2
0 1
0 2
4 2

but when I run it via code the datareader returns with only one result.

Hope someone overcome this and could help
-------------------------------------------------------------------------------------------------------------------------
The Stored procedure

CREATE PROCEDURE FetchData @columnlist char(255), @recordlist
char(255), @tablename char(255)

AS
BEGIN
SET NOCOUNT ON

DECLARE @SQL varchar(8000)

SET @SQL =
' SELECT ' + @columnlist + ' FROM ' + @tablename + 'WHERE rd_id IN
(' + @recordlist + ')'

EXEC(@SQL)
END
GO

-------------------------------------------------------------------------------------------------------------------------
The code
string sqlCommand = "FetchData";

DBCommandWrapper dbCommandWrapper =
db.GetStoredProcCommandWrapper(sqlCommand);
dbCommandWrapper.AddInParameter("@columnlist", DbType.String,
sColumn);
dbCommandWrapper.AddInParameter("@recordlist", DbType.String, records);
dbCommandWrapper.AddInParameter("@tablename", DbType.String, table);
dataReader = db.ExecuteReader(dbCommandWrapper);
do {
while (dataReader.Read()) {
try{
o = dataReader["rms_v1_max"]; }catch{}
try{
o = dataReader["rms_v1_min"]; }catch{}

}
} while (dataReader.NextResult());
*****The innner while runs only one time because the NextResult return
false
Thanks in advance
Oren

Nov 20 '05 #2
Nicholas, thank you for your response,

Even if the NextResult should only run once I expect the datareader to
return first the col1 items:0,0,4 then col2 items: 1,2,2
In reality it only returns col1 items.
I have change the code in a way that I don't use stored procedure but
two select stetments and the datareader behave as It should, hence
returns the col1 items after the first iteration and then after the
NextResult, in the second inner loop iteration the values of col2.

Is it ring a bell to you or to anyone?

Nov 20 '05 #3

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

Similar topics

1
by: VIJAY KUMAR | last post by:
Hi, Problem: Return ArrayList where Values are Added using DataReader. Note: My Data Reader returns M Columns and N Rows I am using DataReader in Data Access layer. I want to return this...
2
by: Islam Elkhayat | last post by:
In my C# Web Application I need to fill a textbox with DataReader and use a Next Button to view next value... I created the Datareader in the Page_Load but everytime it get result of the First...
6
by: Grant | last post by:
I am connecting to an access database using a datareader in C#. I get results when I run a certain query from Access but when I run it from Code it does not retrieve any results. I have put a stop...
14
by: Jacko | last post by:
Hi guys, Say I made a SELECT statement to my sql DB that would return 50 rows that I will use a sqldatareader to access. Instead of iterating through each and every row of the datareader, I'd...
2
by: Martin Raychev | last post by:
Hi all, I have the following problem: I have a private method that returns a SqlDataReader. For this to work I have not to close the DB connection in the above method. I do this only to
20
by: Mark | last post by:
Hi all, quick question , a DataView is memory resident "view" of data in a data table therefore once populated you can close the connection to the database. Garbage collection can then be used to...
3
by: Lubomir | last post by:
Hi, I have a class A with a public method GetReader: public OleDbDataReader GetReader() { SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings); SqlCommand...
3
by: tshad | last post by:
I am trying to set up a class to handle my database accesses. I can't seem to figure out how to get the return value from my dataReader from these routines (most of which I got elsewhere). They...
3
by: tshad | last post by:
Is there a way to databind a datareader to 2 different dropdownlists? Something like: StoredSearches.DataSource=objCmd.ExecuteReader StoredSearches.DataValueField="SearchID"...
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: 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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
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,...
0
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...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.