473,394 Members | 1,693 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,394 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 1701
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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
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
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
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
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...

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.