473,498 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I show the results of a stored procedure in a datagrid?

Jim
Can someone, please, show me how to display the results of
a stored procedure in a VB.NET datagrid on a winform? I'm
a newbie.

Here's my SQL 2000 stored precedure that returns the
status of SQL Jobs as a table.

==================================================
CREATE PROCEDURE [dbo].[GetRunningJobs] AS

EXEC msdb.dbo.sp_help_job @execution_status = 0

GO
==================================================
Thanks,

Jim
Nov 20 '05 #1
6 2696
Create a dataadapter and assign the select query to this stored proc in your
database. Then, you could create a strongly typed dataset from this, and
assign your datagrid's datasource to your new dataset.

Peace,
cege
"Jim" <an*******@discussions.microsoft.com> wrote in message
news:05****************************@phx.gbl...
Can someone, please, show me how to display the results of
a stored procedure in a VB.NET datagrid on a winform? I'm
a newbie.

Here's my SQL 2000 stored precedure that returns the
status of SQL Jobs as a table.

==================================================
CREATE PROCEDURE [dbo].[GetRunningJobs] AS

EXEC msdb.dbo.sp_help_job @execution_status = 0

GO
==================================================
Thanks,

Jim

Nov 20 '05 #2
Jim
It's not a select query. I can do select queries. I can
start a stored procedure and get the single integer result
that says the procedure completed. I just can't seem to
get the returned table into a datagrid.

Jim
-----Original Message-----
Create a dataadapter and assign the select query to this stored proc in yourdatabase. Then, you could create a strongly typed dataset from this, andassign your datagrid's datasource to your new dataset.

Peace,
cege
"Jim" <an*******@discussions.microsoft.com> wrote in messagenews:05****************************@phx.gbl...
Can someone, please, show me how to display the results of a stored procedure in a VB.NET datagrid on a winform? I'm a newbie.

Here's my SQL 2000 stored precedure that returns the
status of SQL Jobs as a table.

==================================================
CREATE PROCEDURE [dbo].[GetRunningJobs] AS

EXEC msdb.dbo.sp_help_job @execution_status = 0

GO
==================================================
Thanks,

Jim

.

Nov 20 '05 #3
Dude...

it has to be a select query... thats how data grids work... if you want to
return a single result from a stored proc, don't use a datagrid. Thats like
using a backhoe to plant a daisy...

and if its a "returned table" then yes, thats a select query.

"Jim" <an*******@discussions.microsoft.com> wrote in message
news:0c****************************@phx.gbl...
It's not a select query. I can do select queries. I can
start a stored procedure and get the single integer result
that says the procedure completed. I just can't seem to
get the returned table into a datagrid.

Jim
-----Original Message-----
Create a dataadapter and assign the select query to this

stored proc in your
database. Then, you could create a strongly typed

dataset from this, and
assign your datagrid's datasource to your new dataset.

Peace,
cege
"Jim" <an*******@discussions.microsoft.com> wrote in

message
news:05****************************@phx.gbl...
Can someone, please, show me how to display the results of a stored procedure in a VB.NET datagrid on a winform? I'm a newbie.

Here's my SQL 2000 stored precedure that returns the
status of SQL Jobs as a table.

==================================================
CREATE PROCEDURE [dbo].[GetRunningJobs] AS

EXEC msdb.dbo.sp_help_job @execution_status = 0

GO
==================================================
Thanks,

Jim

.

Nov 20 '05 #4
Jim
Maybe I'm confused? Are you saying that "GetRunningJobs"
is my SELECT statment? This returns a table.

Here's where I'm getting stuck:

Dim myConn As SqlConnection = New _
SqlConnection
("server=abc;database=Northwind;integrated security=SSPI")
Dim myDA As New SqlDataAdapter

myDA.SelectCommand = New SqlCommand
myDA.SelectCommand.Connection = myConn

'-------What do I do here?
myDA.SelectCommand.CommandText = "GetRunningJobs"
myDA.SelectCommand.CommandType = _
CommandType.StoredProcedure
'-------
' OR
'-------
myDA.SelectCommand.CommandText = "EXEC GetRunningJobs"
myDA.SelectCommand.CommandType = _
CommandType.Text
'--------

myConn.Open()

' Then which execute command do I use and how?
myDA.SelectCommand.????????????
.ExecuteNonQuery
.ExecuteReader
myConn.Close()
Jim

Nov 20 '05 #5
Jim
Thanks for your help. The light bulb just lit up in my
head! Here's how I got it to work:

=========
myDA.SelectCommand = New SqlCommand
myDA.SelectCommand.Connection = myConn

'Note I'm running the stored procedure through t-sql.
myDA.SelectCommand.CommandText = "Exec GetRunningJobs"

myDA.SelectCommand.CommandType = CommandType.Text

myConn.Open()
myDA.SelectCommand.ExecuteNonQuery()
myDA.Fill(myDS, "Jobs")
myConn.Close()

DataGrid1.DataSource = myDS
DataGrid1.DataMember = "Jobs"
=========

Jim
Nov 20 '05 #6
Awesome. =) Nice job.
"Jim" <an*******@discussions.microsoft.com> wrote in message
news:01****************************@phx.gbl...
Thanks for your help. The light bulb just lit up in my
head! Here's how I got it to work:

=========
myDA.SelectCommand = New SqlCommand
myDA.SelectCommand.Connection = myConn

'Note I'm running the stored procedure through t-sql.
myDA.SelectCommand.CommandText = "Exec GetRunningJobs"

myDA.SelectCommand.CommandType = CommandType.Text

myConn.Open()
myDA.SelectCommand.ExecuteNonQuery()
myDA.Fill(myDS, "Jobs")
myConn.Close()

DataGrid1.DataSource = myDS
DataGrid1.DataMember = "Jobs"
=========

Jim

Nov 20 '05 #7

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

Similar topics

4
7144
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...
0
2629
by: Amber | last post by:
Stored procedures are faster and more efficient than in-line SQL statements. In this article we will look at two SQL Server stored procedures; one using an input parameter and one not, and see how...
4
2977
by: Mike Dinnis | last post by:
Hi, I've been working through a number of turorials to try to learn more about retrieving data from a SQL database. I think i've mastered techniques where i create a sql string in the page and...
0
1889
by: Rob | last post by:
I doubt this is the best way to do it, but what I came up with was to hide the XML in an HTML Comment then edit the file deleting the HTML stuff and keep the XML results. If anyone has a better...
2
2228
by: Max | last post by:
Is it possible or more effecient to use a stored procedure to populate a datagrid when using datagrid or custom paging? Is it (ADO.NET?) pulling the entire table into the dataset or is it just...
5
2823
by: microsoft.private.windows.netserver.setup | last post by:
I have a very strange thing occurring in the program. I have a dataset retrieved from a stored procedure that just select * from a table. I then try to use the SQlCommandBuilder on the dataset,...
1
1253
by: .Net Sports | last post by:
i have an aliased column in an sql statement that works fine when displaying its output in a datagrid, but when I transfer the sql statement into a stored procedure , the datagrid can't see it. I...
2
1745
by: Andrew Cooper | last post by:
Greetings, I'm creating a website using ASP.NET. In creating my DAL I've got a Table Adapter that I've set up to use an existing Stored Procedure from an SQL Server 2000 database. However,...
3
2807
by: FrustratedNoob | last post by:
I've got a database that I've been working on for over a year and a half but I've just recently finished the back end to the point of feeling comfortable with starting on a front end. So while...
0
7005
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
7168
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
7210
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...
1
6891
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...
0
5465
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,...
0
4595
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...
0
3096
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...
0
1424
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 ...
0
293
bsmnconsultancy
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...

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.