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

how to read multiple rows from Stored procedure with cursors

I am trying to read multiple rows from an SP into a datalist.

I can easily read and display multiple rows if I use a select statement but when I call an SP to send me a few rows, I only get back the first row. I can also read multiple rows from SP if I have a single select statement in the S

Here is the code:
System.Data.SqlClient.SqlCommand cm;
System.Data.SqlClient.SqlDataReader dr = null;

cm = new System.Data.SqlClient.SqlCommand();
cm.Connection = new System.Data.SqlClient.SqlConnection();
connect......
DataSet ds = new DataSet(); // I don't really need/use this!!!
cm.CommandType = System.Data.CommandType.StoredProcedure;
cm.CommandText = "[getAllTransactions]";

add parameters for SP.....

dr = cm.ExecuteReader();
transListData.DataSource=dr;
transListData.DataBind();
dr.Close();
.....

Could someone help?

Thanks
Merdaad
Jul 21 '05 #1
1 3794
Cor
Hi Merdaad,

There are always things that belongs to each other,
A datareader is special for reading streaming data from a database.

To get a database you can use the dataadapter(also with stored procedures).

I have changed your code a little here in this message, if it gets errors
try to correct or message back.
using System.Data.SqlClient;
SqlCommand cm;
com = new SqlCommand();
Connection conn = new SqlConnection("connectionString");
connect......
DataSet ds = new DataSet(); // I don't really need/use this!!!
com.Connection = conn;
com.CommandType = System.Data.CommandType.StoredProcedure;
com.CommandText = "[getAllTransactions]";
add parameters for SP.....
SqlClient.SqlDataAdapter da = new SqlClient.SqlDataAdapter(com);
da.fill(ds);
transListData.DataSource=ds;
transListData.DataBind();
///

I changed cm in com because it in the else is to confusing with the currency
manager, you will see you use that soon.

Give it a try?

Cor
Jul 21 '05 #2

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

Similar topics

3
by: JB | last post by:
To anyone that is able to help.... What I am trying to do is this. I have two tables (Orders, and OrderDetails), and my question is on the order details. I would like to set up a stored...
3
by: - | last post by:
I have a country table with code and name columns and create a stored procedure 'get_countries()' but have no idea what is the syntax to return multiple rows. I have searched the newsgroups and...
3
by: wxbuff | last post by:
I have a report based on our product names that consists of two parts. Both insert data into a temporary table. 1. A single grouped set of results based on all products 2. Multiple tables based...
1
by: merdaad | last post by:
I am trying to read multiple rows from an SP into a datalist. I can easily read and display multiple rows if I use a select statement but when I call an SP to send me a few rows, I only get back...
16
by: Randy Harris | last post by:
I was inspired by the recent discussion of returning multiple recordsets to ADO from a stored procedure. (Amazed is probably more accurate). I asked about how to accomplish same with Oracle and...
28
by: mooreit | last post by:
The purpose for my questions is accessing these technologies from applications. I develop both applications and databases. Working with Microsoft C#.NET and Microsoft SQL Server 2000 Production and...
5
by: Wael | last post by:
Hi, I have the following stored procedure that does some processing and puts the result in a temporary table. I tried several things that procedure to display output that I can access with...
1
by: Kburton | last post by:
All, I am trying to declare a cursor on global temporary table. I declared the global temporary table first and then the cursor but I got the following error: 42601(-104) SQL0104N An...
11
by: Ganesh R | last post by:
Hi Friends... Can anyone plz help me out i'm stuck .... I want to delete multiple records from a data grid using cursors.the parameter for the stored procedure is an comma seperated string(of...
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:
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...

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.