Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
sqlCon.Open();
SqlCommand cmd = new SqlCommand("procDeliveryStock", sqlCon);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@id", labelID.Text));
cmd.Parameters.Add(new SqlParameter("@date", dateTimePicker1.Text));
cmd.Parameters.Add(new SqlParameter("@description", txtItemDescription.Text));
cmd.Parameters.Add(new SqlParameter("@dosage", txtDosage.Text));
cmd.Parameters.Add(new SqlParameter("@qty", txtQty.Text));
cmd.Parameters.Add(new SqlParameter("@selling", txtSelling.Text));
cmd.Parameters.Add(new SqlParameter("@receiving", txtReceiving.Text));
cmd.Parameters.Add(new SqlParameter("@plus", txtQty.Text));
sqlCon.Close();
and heres my Store Procedure
SQL
USE [BotikaNiChauncey]
GO
/****** Object: StoredProcedure [dbo].[procDeliveryStock] Script Date: 04/26/2014 04:22:34 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[procDeliveryStock]
(
@id INT, @date DATETIME,
@description VARCHAR(50),
@dosage VARCHAR(50),
@selling MONEY,
@receiving MONEY,
@qty INT,
@plus INT,
@minus INT,
@stock INT 
)
AS
BEGIN
SET NOCOUNT ON;
BEGIN TRANSACTION 
INSERT INTO Delivery
(
id, date, description, dosage, qty, selling, receiving
)
values
( 
@id, @date, @description, @dosage, @qty, @selling, @receiving
)
IF @@ERROR = 0
BEGIN 
INSERT INTO StockCard
(
descripton,dosage,[+],[-], stock
)
VALUES
(
@description, @dosage, @plus, @minus, @stock 
)	
IF @@ERROR = 0
BEGIN	
COMMIT TRANSACTION
END
ELSE
BEGIN	
ROLLBACK TRANSACTION	
END
END
ELSE
BEGIN
ROLLBACK TRANSACTION
END

END
My problem is it is not saving in the database but there is no error on runtime.

Thanks in Advance
Posted
Updated 26-Apr-14 1:39am
v2
Comments
Manas Bhardwaj 26-Apr-14 7:42am    
Use SQL Profiler and check what's happening.

1 solution

you need to execute the command

put cmd.ExecuteNonQuery(); before closing the connection
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900