I have been trying to make this code block work, but I can't seem to find the error in it. It doesn't return the value that I am looking for. I would try to run the SQL statement in workbench and it returns my desired number of rows(which is 3).
try
{
using (MySqlConnection con = new MySqlConnection(GlobalValues.ConnectionString))
{
using (MySqlCommand cmd = new MySqlCommand())
{
cmd.CommandText =
@"
SELECT strDetPremID, strPremiseName
FROM tbldetailprem
INNER JOIN tblpremise ON strDetPremID = strPremiseID
WHERE strDetPremContID = @id;
;
"
;
cmd.Parameters.AddWithValue("@id", id);
cmd.Connection = con;
using (MySqlDataAdapter da = new MySqlDataAdapter(cmd))
{
con.Open();
cmd.ExecuteNonQuery();
this.Clear();
da.Fill(this);
con.Close();
}
}
}
}
catch (MySqlException ex)
{
MessageBox.Show(ex.ToString() + " - " + ex.Number);
}
Can you please tell me what's wrong with this code
3? You're also not affecting any rows by selecting.SELECTstatement, so why are you doingExecuteNonQuery?MySqlDataAdapter.ExecuteNonQuery. Also it's not clear what part of that query should give you a result of only 3.