PC Review


Reply
Thread Tools Rate Thread

Command Execute

 
 
JMM B
Guest
Posts: n/a
 
      10th Sep 2004
In the code bellow, I tried:
this.sqlCommand1.ExecuteScalar();
this.sqlCommand1.ExecuteReader();
this.sqlCommand1.ExecuteNonQuery();
All work! But, What would be the best to choose for the mensioned Stored
Procedure?
thanks.

this.sqlCommand1.Parameters["@CustomerID"].Value = this.textBox1.Text;
this.sqlConnection1.Open();
this.sqlCommand1.ExecuteScalar();
this.label1.Text =
this.sqlCommand1.Parameters["@RETURN_VALUE"].Value.ToString();
this.sqlConnection1.Close();
this.label2.Text =
this.sqlCommand1.Parameters["@CompanyName"].Value.ToString();

ALTER PROCEDURE dbo.CountOrders

(
@CustomerID nchar(5),
@CompanyName nvarchar(40) OUTPUT
)

AS
SET NOCOUNT ON

DECLARE @OrdersCount int

SELECT @CompanyName = Customers.CompanyName, @OrdersCount =
COUNT(Orders.OrderID)
FROM Customers INNER JOIN Orders
ON Customers.CustomerID = Orders.CustomerID
WHERE (Customers.CustomerID = @CustomerID)
GROUP BY Customers.CompanyName

RETURN @OrdersCount

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
 
Jared
Guest
Posts: n/a
 
      10th Sep 2004
I would use the ExecScalar or ExecNonQuery.
Output parameters can stll be accessed. if you use the ExecNonQuery method,
or you can just return the count in the select statement and use the
ExecScalar method (first row, first col).


"JMM B" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> In the code bellow, I tried:
> this.sqlCommand1.ExecuteScalar();
> this.sqlCommand1.ExecuteReader();
> this.sqlCommand1.ExecuteNonQuery();
> All work! But, What would be the best to choose for the mensioned Stored
> Procedure?
> thanks.
>
> this.sqlCommand1.Parameters["@CustomerID"].Value = this.textBox1.Text;
> this.sqlConnection1.Open();
> this.sqlCommand1.ExecuteScalar();
> this.label1.Text =
> this.sqlCommand1.Parameters["@RETURN_VALUE"].Value.ToString();
> this.sqlConnection1.Close();
> this.label2.Text =
> this.sqlCommand1.Parameters["@CompanyName"].Value.ToString();
>
> ALTER PROCEDURE dbo.CountOrders
>
> (
> @CustomerID nchar(5),
> @CompanyName nvarchar(40) OUTPUT
> )
>
> AS
> SET NOCOUNT ON
>
> DECLARE @OrdersCount int
>
> SELECT @CompanyName = Customers.CompanyName, @OrdersCount =
> COUNT(Orders.OrderID)
> FROM Customers INNER JOIN Orders
> ON Customers.CustomerID = Orders.CustomerID
> WHERE (Customers.CustomerID = @CustomerID)
> GROUP BY Customers.CompanyName
>
> RETURN @OrdersCount
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



 
Reply With Quote
 
William \(Bill\) Vaughn
Guest
Posts: n/a
 
      10th Sep 2004
ExecuteNonQuery.
Don't return any unnecessary rowsets--they're expensive.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________

"Jared" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I would use the ExecScalar or ExecNonQuery.
> Output parameters can stll be accessed. if you use the ExecNonQuery
> method, or you can just return the count in the select statement and use
> the ExecScalar method (first row, first col).
>
>
> "JMM B" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> In the code bellow, I tried:
>> this.sqlCommand1.ExecuteScalar();
>> this.sqlCommand1.ExecuteReader();
>> this.sqlCommand1.ExecuteNonQuery();
>> All work! But, What would be the best to choose for the mensioned Stored
>> Procedure?
>> thanks.
>>
>> this.sqlCommand1.Parameters["@CustomerID"].Value = this.textBox1.Text;
>> this.sqlConnection1.Open();
>> this.sqlCommand1.ExecuteScalar();
>> this.label1.Text =
>> this.sqlCommand1.Parameters["@RETURN_VALUE"].Value.ToString();
>> this.sqlConnection1.Close();
>> this.label2.Text =
>> this.sqlCommand1.Parameters["@CompanyName"].Value.ToString();
>>
>> ALTER PROCEDURE dbo.CountOrders
>>
>> (
>> @CustomerID nchar(5),
>> @CompanyName nvarchar(40) OUTPUT
>> )
>>
>> AS
>> SET NOCOUNT ON
>>
>> DECLARE @OrdersCount int
>>
>> SELECT @CompanyName = Customers.CompanyName, @OrdersCount =
>> COUNT(Orders.OrderID)
>> FROM Customers INNER JOIN Orders
>> ON Customers.CustomerID = Orders.CustomerID
>> WHERE (Customers.CustomerID = @CustomerID)
>> GROUP BY Customers.CompanyName
>>
>> RETURN @OrdersCount
>>
>> *** Sent via Developersdex http://www.developersdex.com ***
>> Don't just participate in USENET...get rewarded for it!

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Execute Batch Command Automatically form Command Shell with Minlogon stuie_norris@yahoo.com.au Windows XP Embedded 1 21st May 2010 01:26 PM
execute batch file does not execute all command lines John Grandy Microsoft C# .NET 3 17th Dec 2009 02:01 AM
How can I execute a command in the command prompt using Visual Bas =?Utf-8?B?RWR1YXJkbzc4?= Microsoft Dot NET 0 16th Jan 2005 06:41 AM
Execute requires the command to have a transaction object when the connection assigned to the command is in a pending local transaction Victor Microsoft ADO .NET 4 27th Apr 2004 10:01 AM
RUN/execute a Command-Line command from an ASP page. Lucas Cowald Microsoft ASP .NET 4 23rd Oct 2003 01:09 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:05 PM.