Oh and also if you have the access and the know-how, use some SQL auditing and check for errors on that side.
Main Topics
Browse All TopicsHello,
Below is the my stored procedure. When I use .ExecuteScalar from VB.NET, I expect the return value from the SP as 0 or 1. But I always get blank i.e. "". Why?
CREATE procedure [dbo].[sp_VoidTransaction_
AS
Declare @strSQL as varchar(8000)
Declare @intNewTrnNr as Integer
BEGIN TRANSACTION
-- Insert voided record into Sales Master
Insert Into Sales_Master( ShipNr, Sales_TrnNr, Partial_Sales_Nr,
ServerID, Table_Nr, Account_Nr, Routing_Account, Transaction_Status, Cabin_Nr, Sales_date,
Cruise_Nr, Outlet_Nr, Stock_Code, NetSalesPrice, GrossSalesPrice, Gratuity, Discount,
IsTaxApplicable, TaxType, TaxAmount, Amount_due, IsSalesDeducted_FromStock,
Payment_Type, IsSalePartiallyClosed, NewServerID, Extra_Gratuities, isSelected, AIAccount_Nr,
AllInclusiveDiscount, IsAllInclusive, VoidFlag )
Select ShipNr, Sales_TrnNr, Partial_Sales_Nr,
ServerID, Table_Nr, Account_Nr, Routing_Account, Transaction_Status, Cabin_Nr, @Sales_date,
Cruise_Nr, Outlet_Nr, Stock_Code, (-1) * NetSalesPrice, (-1) * GrossSalesPrice, (-1) * Gratuity,
(-1) * Discount, IsTaxApplicable, TaxType, (-1) * TaxAmount, (-1) * Amount_due, IsSalesDeducted_FromStock,
Settlement_type, Payment_Type, IsSalePartiallyClosed, NewServerID, (-1) * Extra_Gratuities,
isSelected, AIAccount_Nr, (-1) * AllInclusiveDiscount, IsAllInclusive, 1
From Sales_Master Where Sales_Master.Transaction_N
-- On error return False
IF @@Error <> 0
BEGIN
ROLLBACK TRANSACTION
Return 0
END
-- Select Transaction_Nr of inserted record
Select @intNewTrnNr = Max(Transaction_Nr) From Sales_Master
-- On error return False
IF @@Error <> 0
BEGIN
ROLLBACK TRANSACTION
Return 0
END
-- Insert into Sales Details
DECLARE @ShipNr As varchar(15)
DECLARE @Batch As smallint
DECLARE @PLU_ID As Int
DECLARE @SortID As smallint
DECLARE @Sales_Qty As smallint
DECLARE @Unit_Price As Numeric(15,2)
DECLARE @PLU_SpecifierID As Int
DECLARE @PLU_SpecifierSurcharge As Numeric (15,2)
DECLARE @TaxPercent As Numeric (15,2)
DECLARE @Discount As Numeric (15,2)
DECLARE SALES_CURSOR CURSOR FOR
SELECT ShipNr, Batch, PLU_ID, SortID, Sales_Qty, Unit_Price, PLU_SpecifierID, PLU_SpecifierSurcharge, TaxPercent, Discount From Sales_Details Where Transaction_Nr = @intTransactionNr
OPEN SALES_CURSOR
FETCH NEXT FROM SALES_CURSOR INTO @ShipNr, @Batch, @PLU_ID, @SortID, @Sales_Qty, @Unit_Price, @PLU_SpecifierID, @PLU_SpecifierSurcharge, @TaxPercent, @Discount
WHILE @@fetch_status=0
BEGIN
INSERT INTO Sales_Details Values(@ShipNr, @intNewTrnNr, @Batch, @PLU_ID, @SortID, (-1) * @Sales_Qty, @Unit_Price, @PLU_SpecifierID, @PLU_SpecifierSurcharge, @TaxPercent, (-1) * @Discount)
FETCH NEXT FROM SALES_CURSOR INTO @ShipNr, @Batch, @PLU_ID, @SortID, @Sales_Qty, @Unit_Price, @PLU_SpecifierID, @PLU_SpecifierSurcharge, @TaxPercent, @Discount
END
CLOSE SALES_CURSOR
DEALLOCATE SALES_CURSOR
-- On error return False
IF @@Error <> 0
BEGIN
ROLLBACK TRANSACTION
Return 0
END
Else
Begin
COMMIT TRANSACTION
RETURN 1
End
GO
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Within your code where you have defined Parameters.Add for (intTransactionNr etc.) you should define another as follows
myCommand.Parameters.Add("
myCommand.Parameters("@myR
or you could simply declare an OUTPUT parameter for your stored procedure and set its value to 0 or 1 within the sp and then define as follows
myCommand.Parameters.Add("
myCommand.Parameters("@myR
myCommand.ExecuteNonQuery(
If myCommandParameters("@myRe
' do something
ELSE
' do something else
End If
HTH
Business Accounts
Answer for Membership
by: FocusynPosted on 2006-04-18 at 05:40:06ID: 16477226
On ExecuteScalar() with stored procedures, most SQL Server-side errors will not throw an exception to your .NET assembly. It will simply return no value. Try putting your Exec command in a try catch block and see if it throws an exception, but my guess is something on the SQL side is causing that.
e
On your code side, also make sure you have explicitly declared COmmandType.StoredProcedur
and added all the sp variables as yourCommand.Parameter.Add etc rather than trying to concatenate a long commandtext string.