this button click event on which i am trying to save the data to database. and it gives me error
procedure or function save_sale_Master has too many arguments specified
private void generatebill_Click(object sender, EventArgs e)
{
SqlCommand cmd;
if (con.State == ConnectionState.Closed)
{
con.Open();
}
System.Data.SqlClient.SqlTransaction _trans = con.BeginTransaction();
cmd = new SqlCommand("", con, _trans);
cmd.Transaction = _trans;
if (!AddEdit)
{
cmd.CommandText = "select_invoice";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@bs1",Convert.ToInt32(BILLSERIES.SelectedIndex));
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adp.Fill(dt);
var Invoice_No = "";
if (dt.Rows.Count>0)
{
Invoice_No = dt.Rows[0]["Invoice_No"].ToString();
newinvoice = GenerateNumber(Invoice_No);
}
else
{
Invoice_No = (BILLSERIES.Text + "00000");
newinvoice = GenerateNumber(Invoice_No);
}
}
try
{
cmd.CommandText = "save_sale_Master";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@acc_no", CUSTOMERACCOUNTNO.Text);
if (AddEdit)
{
cmd.Parameters.AddWithValue("@Invoice_No", INVOICENO.Text);
}
else if (!AddEdit)
{
cmd.Parameters.AddWithValue("@Invoice_No", newinvoice);
}
cmd.Parameters.AddWithValue("@Invoice_Date", invoicedate.Text);
cmd.Parameters.AddWithValue("@PaymentMethod_Code", Convert.ToInt32(MODEOFPAYMENT.SelectedValue));
cmd.Parameters.AddWithValue("@Total_Amount", Convert.ToDouble(TOTAL.Text));
cmd.Parameters.AddWithValue("@Total_Discount", Convert.ToDouble(DISCOUNTAMOUNT1.Text == "" ? "0" : DISCOUNTAMOUNT1.Text));
cmd.Parameters.AddWithValue("@Fright_Charges", Convert.ToDouble(FRIGHTCHARGES.Text == "" ? "0" : FRIGHTCHARGES.Text));
cmd.Parameters.AddWithValue("@GST", Convert.ToInt32(GST.SelectedValue));
cmd.Parameters.AddWithValue("@GST_Amount", Convert.ToDouble(GSTAMOUNT.Text));
cmd.Parameters.AddWithValue("@Total_BillToBePaid", Convert.ToDouble(GRANDTOTAL.Text));
cmd.Parameters.AddWithValue("@RoundingOff", Convert.ToDouble(GRANDTOTAL.Text == "" ? "0" : GRANDTOTAL.Text));
cmd.Parameters.AddWithValue("@remark", remark.Text);
cmd.Parameters.AddWithValue("@spremark", spremark.Text);
cmd.Parameters.AddWithValue("@trans", TRANSPORT.Text);
cmd.Parameters.AddWithValue("@grnno", grn.Text);
cmd.Parameters.AddWithValue("@vichelno", vichle.Text);
cmd.Parameters.AddWithValue("@bs", Convert.ToInt32(BILLSERIES.SelectedValue));
if(AddEdit)
{
cmd.Parameters.AddWithValue("@CALLTYPE", "Update");
}
else if(!AddEdit)
{
cmd.Parameters.AddWithValue("@CALLTYPE", "Insert");
}
int t = cmd.ExecuteNonQuery();
int counter = 0;
if (t > 0)
{
for (counter = 1; counter < itemgrid1.Rows.Count; counter++)
{
cmd.Parameters.Clear();
cmd.CommandText = "save_sale_detail";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Item_Description", itemgrid1.Rows[counter - 1].Cells["Item_Description"].Value);
cmd.Parameters.AddWithValue("@HSN_Code", itemgrid1.Rows[counter - 1].Cells["HSN_Code"].Value);
cmd.Parameters.AddWithValue("@Quantity", Convert.ToInt32(itemgrid1.Rows[counter - 1].Cells["Quantity"].Value));
cmd.Parameters.AddWithValue("@Converstion_Type", itemgrid1.Rows[counter - 1].Cells["Converstion_Type"].Value);
cmd.Parameters.AddWithValue("@Rate", Convert.ToInt32(itemgrid1.Rows[counter - 1].Cells["Rate"].Value));
cmd.Parameters.AddWithValue("@amount", Convert.ToDouble(itemgrid1.Rows[counter - 1].Cells["Amount"].Value));
if (AddEdit)
{
cmd.Parameters.AddWithValue("@units", itemgrid1.Rows[counter - 1].Cells["Unit_Type"].Value);
cmd.Parameters.AddWithValue("@Invoice_No", INVOICENO.Text);
cmd.Parameters.AddWithValue("@CALLTYPE", "Update");
}
if (!AddEdit)
{
cmd.Parameters.AddWithValue("@Invoice_No", newinvoice);
cmd.Parameters.AddWithValue("@units", itemgrid1.Rows[counter - 1].Cells["Unit_Type"].Value);
cmd.Parameters.AddWithValue("@CALLTYPE", "Insert");
}
cmd.ExecuteNonQuery();
}
}
if ( GRANDTOTAL.Text == "")
{
MessageBox.Show("Please Add Items To Grid Along With Price");
}
else if (CUSTOMERNAMETEXT.Text == "")
{
MessageBox.Show("Please Select Customer For Billing");
}
else if (counter == itemgrid1.Rows.Count)
{
_trans.Commit();
MessageBox.Show("DATA HAS BEEN SAVED");
}
}
catch(SqlException err)
{
_trans.Rollback();
MessageBox.Show(err.Message);
}
}
Stored proc is:
CREATE PROCEDURE [dbo].[save_sale_Master]
@acc_no nvarchar(50),
@Invoice_No nvarchar(50),
@Invoice_Date DATE,
@PaymentMethod_Code INT,
@Total_Amount int,
@Total_Discount decimal(9,2),
@Fright_Charges decimal(9,2),
@GST int,
@GST_Amount decimal(9,2),
@Total_BillToBePaid decimal(9,2),
@RoundingOff int,
@remark nvarchar(1000),
@spremark nvarchar(1000),
@trans nvarchar(50),
@grnno int,
@vichelno nvarchar(50),
@bs int,
@CALLTYPE nvarchar(50)
AS
if (@CALLTYPE='Insert')
begin
insert into Invoice_Bills(Invoice_No,Invoice_Date,PaymentMethod_Code,Total_Discount,
Fright_Charges,GST,GST_Amount,Total_BillToBePaid,RoundingOff,Total_Amount,AccountNo,remark,specialremark,
transportername,grnno,vichelno,Bill_series)
values(@Invoice_No,@Invoice_Date,@PaymentMethod_Code,@Total_Discount,
@Fright_Charges,@GST,@GST_Amount,@Total_BillToBePaid,@RoundingOff,@Total_Amount,@acc_no,@remark,@spremark,
@trans,@grnno,@vichelno,@bs)
end
else if (@CALLTYPE='Update')
begin
update Invoice_Bills set
PaymentMethod_Code=@PaymentMethod_Code,
Total_Discount=@Total_Discount,
Fright_Charges=@Fright_Charges,
GST=@GST,
GST_Amount=@GST_Amount,
Total_BillToBePaid=@Total_BillToBePaid,
RoundingOff=@RoundingOff,
Total_Amount=@Total_Amount,
AccountNo=@acc_no,
remark=@remark,
specialremark=@spremark,
transportername=@trans,
grnno=@grnno,
vichelno=@vichelno,
Bill_series=@bs
where Invoice_No=@Invoice_No
end
RETURN 0
What I have tried:
i tried counting all the variables in my stored procedure and even checked spelling but still i am facing the same problem.