Home > Forum > ASP.NET > error in my code so am getting -1 of result while inserting data

error in my code so am getting -1 of result while inserting data

by celv   on May 04, 2015   Category: ASP.NET  |  Views: 1179    |  Points: 5   |  Bronze 
  Reply




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
BEGIN
ROLLBACK
END
ELSE
BEGIN
COMMIT
END
RETURN @Result



Bookmark and Share:
 
  User Reply  | Ask a question  |   Reply 
  Re :error in my code so am getting -1 of result while inserting data   
by Thamil
on May 5 2015 9:22AM
Points : 10
Gold 
Hi Celv,

1. Add this line in the proc after AS
set nocount off;
2. Remove all statements in the proc and try only with insert statement
3. Execute the proc in sqlserver by passing parameters and test whether values are inserting not.
  Re :error in my code so am getting -1 of result while inserting data   
by celv
on May 7 2015 2:12AM
Points : 10
Bronze 
data are inserted for more times .need to avoid duplicate data to delete that's why i choose write this procedure please correct in my proceudure
  Re :error in my code so am getting -1 of result while inserting data   
by Santosh Kumar Bind
on Jul 21 2015 3:22AM
Points : 10
Starter 
where you get the error please specified the details

Recent Post

Latest Posts