I have been facing this timed out Problem more frequently. I have been using MYSQL Database and working on windows application. I have even tried on using having clause but faced the same situation
public bool VerifyStock(string serialnumber)
{
con = new MySqlConnection(connstring);
string readData = "select * from Fn_Inventory where ModelNumber = '" + serialnumber + "'";
cmd = new MySqlCommand(readData, con);
cmd.Parameters.AddWithValue("@ModelNumber", serialnumber);
con.Open();
dr = cmd.ExecuteReader();
if (dr.HasRows)
{
//while (dr.Read())
if (dr.Read())
{
decimal invquntity = Convert.ToDecimal(dr["AvailableQuantity"].ToString());
decimal quantity = Convert.ToDecimal(txtQuantity.Text);
decimal sinvquntity = invquntity - quantity;
if (sinvquntity >= 0)
{
return false;
}
else
{
return true;
}
}
else
{
return false;
}
}
else
{
return false;
}
con.Close();
}
using
statement to dispose your database connections. – Soner Gönül