I am trying to subtract amount paid by customer from the total amount of price but am getting this error.
Error CS0103 The name paid does not exist in the current context
if (txtqty.Text.Length > 0 && txtprice.Text.Length > 0)
{
float qty2 = !string.IsNullOrEmpty(txtqty.Text.Trim()) ? float.Parse(txtqty.Text.Trim()) : float.Parse("0"); ;
float price = !string.IsNullOrEmpty(txtprice.Text.Trim()) ? float.Parse(txtprice.Text.Trim()) : float.Parse("0"); ;
float totalprice = qty2 * price;
float finalprice = totalprice;
if (txtqty.Text.Length > 0 && txtamountpaid.Text.Length > 0)
{
float balance = totalprice - paid;
float totalrem = balance;
using (SqlConnection con = new SqlConnection())
{
con.ConnectionString = str;
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
//Change the query like below
//Make sure the column name matches the with the name provided in code as per your table
cmd.CommandText = "INSERT INTO Vendor_Payment (Date,Vendor,Brand,Item,Quantity,Price,Payment_Status,Payment_Method,Bank_Name,Account_Number,Total,Amount_Paid,Balance) VALUES(@Date,@Vendor,@Brand,@Item,@Quantity,@Price,@Payment_Status,@Payment_Method,@Bank_Name,@Account_Number,@Total,@Amount_Paid,@Balance)";
cmd.Parameters.AddWithValue("@Date", txtdate.Text);
cmd.Parameters.AddWithValue("@Amount_Paid", txtamountpaid.Text);
cmd.Parameters.AddWithValue("@Brand", ddlvendobrands.SelectedItem.Text);
cmd.Parameters.AddWithValue("@SubCategory", ddlsubcategory.SelectedItem.Text);
cmd.Parameters.AddWithValue("@Account_Number", txtaccountno.Text);
cmd.Parameters.AddWithValue("@Vendor", ddlvenddor.SelectedItem.Text);
cmd.Parameters.AddWithValue("@Item", ddlsubcategory.SelectedItem.Text);
cmd.Parameters.AddWithValue("@Quantity", txtqty.Text);
cmd.Parameters.AddWithValue("@Price", txtprice.Text);
cmd.Parameters.AddWithValue("@Payment_Method", ddlpaymentmethod.SelectedItem.Text);
cmd.Parameters.AddWithValue("@Payment_Status", ddlpaymentstatus.SelectedItem.Text);
cmd.Parameters.AddWithValue("@Bank_Name", txtbankname.Text);
cmd.Parameters.AddWithValue("@Total", totalprice);
cmd.Parameters.AddWithValue("@Balance", balance);
con.Open();
inserted = cmd.ExecuteNonQuery();
con.Close();
BindGridreport();
string message = string.Empty;
{
// lblMessage2.Visible = true;
/// lblMessage2.Text = "Data Submitted Successfully";
}
ScriptManager.RegisterClientScriptBlock(btnsave, this.GetType(), "alert", "<script>alert('Data Submitted Successfully ... !!')</script>", false);
// lblMessage2.Text = "Inserted Quantity Is Higher than stock " + GetQuantity().ToString();