Working with a mysql dbase and c#,
Below is the method I created in database class to check if the row exists.
public int CheckRows(string query)
{
try
{
openConnection();
}
catch (MySqlException ex)
{
MessageBox.Show(ex.Message);
}
cmd = new MySqlCommand(query, con);
int read = (Int32)cmd.ExecuteScalar();
return read;
cmd.Dispose();
closeConnection();
}
And the button click event,
private void button2_Click(object sender, EventArgs e)
{
int invoice = Convert.ToInt32(textBox9.Text);
string qry = "Select 1 from purchase where purchId='" + invoice + "'";
int dub = db.CheckRows(qry);
}
Which gives the mentioned exception. What am I doing wrong here?