First of all, please don't use concatenation to form the statement; use parameters:
Simplified Database Access via ADO.NET Interfaces[
^]
Plus, if you can execute one statement, you can execute two, in a transaction is prefered.
If this is SQL Server, you can actually pass multiple statements at once if you like. Or you might choose to write a stored procedure to do it.
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
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