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" ;
DBCommandWrappe r dbCommandWrappe r =
db.GetStoredPro cCommandWrapper (sqlCommand);
dbCommandWrappe r.AddInParamete r("@columnlist" , DbType.String,
sColumn);
dbCommandWrappe r.AddInParamete r("@recordlist" , DbType.String, records);
dbCommandWrappe r.AddInParamete r("@tablename ", DbType.String, table);
dataReader = db.ExecuteReade r(dbCommandWrap per);
do {
while (dataReader.Rea d()) {
try{
o = dataReader["rms_v1_max "]; }catch{}
try{
o = dataReader["rms_v1_min "]; }catch{}
}
} while (dataReader.Nex tResult());
*****The innner while runs only one time because the NextResult return
false
Thanks in advance
Oren 2 3400
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.co m
<or****@gmail.c om> wrote in message
news:11******** **************@ g47g2000cwa.goo glegroups.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" ;
DBCommandWrappe r dbCommandWrappe r = db.GetStoredPro cCommandWrapper (sqlCommand);
dbCommandWrappe r.AddInParamete r("@columnlist" , DbType.String, sColumn); dbCommandWrappe r.AddInParamete r("@recordlist" , DbType.String, records); dbCommandWrappe r.AddInParamete r("@tablename ", DbType.String, table); dataReader = db.ExecuteReade r(dbCommandWrap per); do { while (dataReader.Rea d()) { try{ o = dataReader["rms_v1_max "]; }catch{} try{ o = dataReader["rms_v1_min "]; }catch{}
} } while (dataReader.Nex tResult());
*****The innner while runs only one time because the NextResult return false
Thanks in advance Oren
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? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 result to
Business Layer. But, considering performace and Efficiency, I have to Close
the DataReader Connection.
|
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 row.
If i use a While or For loop i get result of the last row...
How can i check "PostBack" to do so our if there is another way to fill the
textbox and use the Next button to see next result rather than DataReader??
thanx
|
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 point after the string
is created and it is correct. Its an inner join query so I was wandering
whether that is too complicated for a datareader to execute, or if Im
missing something else here?
Heres what Im doing in code:
...
|
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 like to just iterate through,
say, rows 20 through 30.
How can one do this?
|
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
| |
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 "clean up" the DataView once it is not referenced and will not
effect the number of connections to the database.
A DataReader on the other hand always maintains a connection to the database
and must be explicitly closed (Do not rely on garbage...
|
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 myCommand = new SqlCommand("CMRC_Top10List", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
|
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 do work pretty
well, except for the change I made to get the return value.
For example, I have the following:
**********************************************************************
Public Overloads Function RunProcedure( _
ByVal storedProcName...
|
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"
StoredSearches.DataTextField= "SearchName"
StoredSearches.databind()
SearchList.DataSource=objCmd.ExecuteReader
SearchList.DataValueField="SearchID"
SearchList.DataTextField= "SearchName"
|
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,...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
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...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |