473,657 Members | 2,544 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Loading a datagrid/datalist from a Stored procedure that uses cursor

In my datagrid, I call my SP and if I only have a simple select statement, everything comes back fine and all rows get displayed in datagrid using datasource and databind

But if I use a cursor inside the SP (to manipulate data), the data that comes out of the SP can not be displayed in the datagrid. In this case only the first row shows up
Here is aportion of my page_load

System.Data.Sql Client.SqlComma nd cm;
System.Data.Sql Client.SqlDataR eader dr = null;
System.Data.Sql Client.SqlComma nd cm;
//DataSet ds = new DataSet();

cm = new System.Data.Sql Client.SqlComma nd();
cm.Connection = ConnectionStrin g;
cm.Connection.O pen();
cm.CommandType = System.Data.Com mandType.Stored Procedure;
cm.CommandText = "[getTransList]";

dr = cm.ExecuteReade r();
gridListData.Da taSource=dr;
gridListData.Da taBind();
dr.Close();
Nov 15 '05 #1
1 2272
Hi,

Binding the DataGrid to a DataReader is not a good idea. You should create
and populate a DataSet or a DataTable and then bind the grid to those.

Second, ensure you return a valid rowset from your SP. I have little
experience with cursors, but I suppose you should still execute a SELECT
statement to return the rowset after you have finished data manipulation.
You could probably introduce a temp table or a local variable of type TABLE
(given your DB is SQL Server 2000).

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Merdaad" <an*******@disc ussions.microso ft.com> wrote in message
news:2B******** *************** ***********@mic rosoft.com...
In my datagrid, I call my SP and if I only have a simple select statement, everything comes back fine and all rows get displayed in datagrid using
datasource and databind.
But if I use a cursor inside the SP (to manipulate data), the data that comes out of the SP can not be displayed in the datagrid. In this case only
the first row shows up! Here is aportion of my page_load:

System.Data.Sql Client.SqlComma nd cm;
System.Data.Sql Client.SqlDataR eader dr = null;
System.Data.Sql Client.SqlComma nd cm;
//DataSet ds = new DataSet();

cm = new System.Data.Sql Client.SqlComma nd();
cm.Connection = ConnectionStrin g;
cm.Connection.O pen();
cm.CommandType = System.Data.Com mandType.Stored Procedure;
cm.CommandText = "[getTransList]";

dr = cm.ExecuteReade r();
gridListData.Da taSource=dr;
gridListData.Da taBind();
dr.Close();


Nov 15 '05 #2

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

Similar topics

3
2872
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 ?...
4
7175
by: John | last post by:
Hi everyone, I have a stored procedure which I use to query a table. The first part of the stored procedure uses a cursor to update a temp table whilst the second part of the query actually retrieves information from a database table utilising information based on the temp table. My problem is that when I run the procedure, the cursors status is output and therefore becomes part of the result set. I really only want the information...
5
4144
by: mas | last post by:
I have a Stored Procedure (SP) that creates the data required for a report that I show on a web page. The SP does all the work and just returns back a results set that I dump in an ASP.NET DataGrid. The SP takes a product area and a start and end date as parameters. Here are the basics of the SP. 1. Create temp table to store report results, all columns are created that will be needed at this point. 2. Select products and general...
0
1378
by: volodymyr.sapiha | last post by:
I have stored procedure which have one input parameter - cursor. Is there any mechanism to pass parameter to this stored procedure with the help ADO.NET. Thank you.
2
3326
by: Eli | last post by:
Hi all We currently have a strange problem with calling a Stored Procedure (SQL Database) in our C# Project. The only error I get is "System error" which says a lot :) Background: We have several stored procedures to Insert and update datas in our SQL database. Some stored procedures are smaller (insert datas in only one table) and some of them are quite big (insert datas in several
1
7508
by: peaceburn | last post by:
Hi, I'm gonna pull my hair in the coming days with these DB2 stored procedures. So the issue, let's assume a simple stored procedure like this : CREATE PROCEDURE MYSCHEMA.PROCEDURE1 ( ) DYNAMIC RESULT SETS 1 ------------------------------------------------------------------------
9
2454
by: Frawls | last post by:
Hi I Am am having problems with a stored Procedure that i wrote. Basically whats happening is that the Stored procedure Runs fine when i EXECUTE it in SQL Query analyzer. But when i debug through the application in Visual Studio .NET 2003 the application an exception when it executes the query.
1
11917
by: mcasaurabhsumit | last post by:
differences between stored procedure and cursor
0
1583
by: Chris Padian | last post by:
It must be possible to pass a cursor as an input parameter to a DB2 Stored Procedure. The cursor would point to a location of an array of, let's say, employee numbers to be passed and used to update DB2 tables.
9
2019
by: ookdeh | last post by:
Dear all, i'm facing a problem with my storedprocedure which happened when i ran my web application and reach to the point where my class invoke this storedprocedure, my SP contains a cursor that built his sql according to certain condition, so i put the "SET @cur Cursor For....." inside the if block (definitely i've declared it under AS keyword directly) and this SP is working well inside sql server(I've tested it), BUT when my ASP.net...
0
8392
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
8305
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
8732
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...
1
8503
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,...
0
8605
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
7324
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...
1
6163
isladogs
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...
0
5632
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();...
2
1953
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.