473,406 Members | 2,273 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,406 software developers and data experts.

Placing a Stored Procedure Expression in .Net

edb
Hi again

I have a stored procedure that looks like this.
CREATE PROCEDURE usp_GetCustomers AS

SELECT customer_id, customer, COUNT(*)
FROM dbo.Customer
GROUP BY customer_id, customer
UNION ALL
SELECT NULL, NULL, COUNT(*) AS Expr1
FROM dbo.Customer
GO

It works great in Query Analyzer and Syntax is successful
in SQL 2000. The expression in Query Analyzer is read as a
field with no name. The total comes up 33 which is Expr1,
what I need.

How do I grab this Stored Procedure and place it into a
label in .Net?

I really appreciate your input. I am not too smart.

Thx bunches

edb
Jul 21 '05 #1
2 1702
You need to create a connection object and give it a valid connection
string. You'll need a command object and set it's connection to the
aforementioned connection. Set the CommandText of the Command to
"usp_GetCustomers". Declare a Datareader object. Make sure the connection
is open...
if cn.State <> ConnectionState.Open then cn.Open

then seet the commandtype to StoredProcedure.

finally, hit myDataReader = cmd.ExecuteReader, enlcose this in a try catch
block, same for your connection.Open statement.

After that,...

While dr.Read
myLabel.text &= dr(0)
End While

finally, close the reader dr.Close

However, I don't see how you can set a set like this to a Label's text. It
will be unreadable. Whatever you want to do with it, remember that DR(0)
will be customer_id, dr(1) will be customer and dr(3) will be Count.

HTH,

Bill
"edb" <m1**@dm2000.com> wrote in message
news:b4****************************@phx.gbl...
Hi again

I have a stored procedure that looks like this.
CREATE PROCEDURE usp_GetCustomers AS

SELECT customer_id, customer, COUNT(*)
FROM dbo.Customer
GROUP BY customer_id, customer
UNION ALL
SELECT NULL, NULL, COUNT(*) AS Expr1
FROM dbo.Customer
GO

It works great in Query Analyzer and Syntax is successful
in SQL 2000. The expression in Query Analyzer is read as a
field with no name. The total comes up 33 which is Expr1,
what I need.

How do I grab this Stored Procedure and place it into a
label in .Net?

I really appreciate your input. I am not too smart.

Thx bunches

edb

Jul 21 '05 #2
Hi,

I'd like to propose a different solution. I assume you are looking to retrieve a list of clients, and the display the total at the
bottom of the page? The code William put forth will work for listing the clients, but then I'd remove the Union All from the stored
procedure, and do the following:

CREATE PROCEDURE usp_GetCustomers AS

SELECT customer_id, customer, COUNT(*)
FROM dbo.Customer
GROUP BY customer_id, customer

SELECT COUNT(*) AS Customers
FROM dbo.Customer
GO

Then in your code, you can iterate through the list as follows:

While dr.Read
myLabel.text &= dr(0)
End While

Then, to get to the total:

If (dr.NextResult())
If (dr.Read())
totalLable.Text = dr(0).ToString()
End If
End If

HTH

Thys Brits
MCSD/MCSD.Net

"edb" <m1**@dm2000.com> wrote in message news:b4****************************@phx.gbl...
Hi again

I have a stored procedure that looks like this.
CREATE PROCEDURE usp_GetCustomers AS

SELECT customer_id, customer, COUNT(*)
FROM dbo.Customer
GROUP BY customer_id, customer
UNION ALL
SELECT NULL, NULL, COUNT(*) AS Expr1
FROM dbo.Customer
GO

It works great in Query Analyzer and Syntax is successful
in SQL 2000. The expression in Query Analyzer is read as a
field with no name. The total comes up 33 which is Expr1,
what I need.

How do I grab this Stored Procedure and place it into a
label in .Net?

I really appreciate your input. I am not too smart.

Thx bunches

edb

Jul 21 '05 #3

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

Similar topics

3
by: Jarrod Morrison | last post by:
Hi all Im relatively new to using stored procedures and im not sure if it is possible to do what I am trying to do so any help here is greatly appreciated. I am using the variable @MachineName...
2
by: nbohana | last post by:
I am trying to code an compile a stored procedure without success. So I generated one using Microsoft Visule C# .Net. and it follows. One of the problems is that it will not compile. Some of the...
2
by: edb | last post by:
Hi again I have a stored procedure that looks like this. CREATE PROCEDURE usp_GetCustomers AS SELECT customer_id, customer, COUNT(*) FROM dbo.Customer GROUP BY customer_id, customer
2
by: priyamtheone | last post by:
I'm trying to create a stored procedure in MSSQL Server 2005 that'll perform the following jobs: 1) Create a login. 2) Create an user in TestDB database for the login created in step 1. 3) Assign...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
0
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...
0
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
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...

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.