I created a SQL query and it should update the database after the payment is made, but when I hit the save button, nothing happens, I don’t even get an error.
Save button code:
public override void btnsave_Click(object sender, EventArgs e)
{
string qry = @" Update tblMain set total=@tot,recevid=@rec,change=@cha,status ='پرداخت شد' where MainID=@id";
Hashtable ht = new Hashtable();
ht.Add("@id", MainID);
ht.Add("@tot", TextBillAmount.Text);
ht.Add("@rec", TextRecive.Text);
ht.Add("@cha", TextChenge.Text);
if (Mainclass.SQL(qry, ht) > 0)
{
guna2MessageDialog1.Buttons = Guna.UI2.WinForms.MessageDialogButtons.OK;
guna2MessageDialog1.Show("با موفقیت ذخیره شد");
this.Close();
}
}
And this is the main class SQL code:
public static int SQL(string qry, Hashtable ht)
{
int res = 0;
try
{
SqlCommand cmd = new SqlCommand(qry, con);
cmd.CommandType = CommandType.Text;
foreach (DictionaryEntry item in ht)
{
cmd.Parameters.AddWithValue(item.Key.ToString(), item.Value);
}
if (con.State == ConnectionState.Closed)
{
con.Open();
}
res = cmd.ExecuteNonQuery();
if (con.State == ConnectionState.Open)
{
con.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
con.Close();
}
return res;
}
So far, I have not had such a problem, and if there was a problem, I would at least receive an error message, but this time, nothing happened at all.
10