error in insert of data in asp.net using procedure

Posted by Selvimca under ASP.NET on 5/5/2015 | Points: 10 | Views : 408 | Status : [Member] | Replies : 1
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




Responses

Posted by: Jayakumars on: 5/8/2015 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi

What issue facing for this check this attachments working your procedure what you facing attached snapshots
I have attached snap shots check and let me know.
 Download source file

Mark as Answer if its helpful to you

Selvimca, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response