hey, i made db connection in C# with SQL but there is some drawbacks which i want to cover it. e.g. when i update even if there if no record it will not show an error also will not UPDATE. Same case with DELETE.
private void button3_Click(object sender, EventArgs e)
{
setData();
bool flag = db.UpdateData("UPDATE trytb SET Name = '"+dc.Name+"' WHERE ID = '"+dc.ID+"'");
if (flag)
MessageBox.Show("Record Updated");
else
MessageBox.Show("Not Updated");
}
public bool DeleteData(string qry)
{
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(qry, conn);
cmd.ExecuteNonQuery();
flag = true;
conn.Close();
return flag;
}
catch
{
return flag;
}
}
Your flag variable is being set to true unconditionally. You should set it to true based on the return value of
cmd.ExecuteNonQuery(). that will tell you if zero or more records were updated/deleted. And based on that, you can set your flag.