使用mysql dbase和c#,
下面是我在数据库类中创建的方法,用于检查行是否存在。
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();
}
按钮点击事件,
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);
}
这给出了上述例外情况。我在这里做错了什么?