try
{
bilnumber();
// partyname();
con = new SqlConnection(s);
con.Open();
string qry = "sectionexpenses";
cmd = new SqlCommand(qry, con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@sectionname", SqlDbType.VarChar).Value = Sectionselect.Text;
// cmd.Parameters.Add("@Expensestype", SqlDbType.VarChar).Value = DropDownList1.Text;
cmd.Parameters.Add("@ExpensesName", SqlDbType.VarChar).Value = Ddexpenz.Text;
cmd.Parameters.Add("@Date", SqlDbType.VarChar).Value = TdATE.Text;
cmd.Parameters.Add("@BillNo", SqlDbType.VarChar).Value = bil;
cmd.Parameters.Add("@BillAmount", SqlDbType.Float).Value = bamountsave.Text;
cmd.Parameters.Add("@currentdate", SqlDbType.VarChar).Value = TextBox4.Text;
cmd.Parameters.Add("@partydetz", SqlDbType.VarChar).Value = bil;
cmd.Parameters.Add("@bdate", SqlDbType.DateTime).Value = DateTime.ParseExact(TdATE.Text, "MM/dd/yyyy", CultureInfo.InvariantCulture);
int rs = cmd.ExecuteNonQuery();
if (rs == 1)
Response.Write("<script>alert('Data Inserted Successfully!')</script>");
snoi.Visible = false;
Printdata.Focus();
}
else
Response.Write("<script>alert('Data Not Inserted !')</script>");
catch
throw;
My procedure
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[sectionexpenses]
(@sectionname varchar(30),
@ExpensesName varchar(max),
@Date varchar(30),
@BillNo varchar(max),
@BillAmount float,
@currentdate varchar(50),
@partydetz varchar(max),
@bdate datetime)
AS
DECLARE @Result int
BEGIN TRANSACTION
IF EXISTS
(
SELECT * FROM expenzsection WHERE sectionname=@sectionname
and partydetz=@partydetz and BillNo=@BillNo and BillAmount=@BillAmount
)
BEGIN
SELECT @Result = -1
END
ELSE
begin
insert into Expenzsection(sectionname,ExpensesName,Date,BillNo,BillAmount,currentdate,partydetz,bdate)
values
@sectionname,@ExpensesName,@Date,@BillNo,@BillAmount,@currentdate,@partydetz,@bdate
SELECT @Result = @@ERROR
end
IF @Result <> 0
ROLLBACK
COMMIT
RETURN @Result