Get the value of MySQL
P粉323374878
P粉323374878 2024-04-06 14:45:26
0
1
534

Since yesterday, I'm trying to get this value (see picture), I've tried using "mysqlreader, executescalar, etc." but I can't get the number of rows.

What I want to do is this:

If the result is 0, do nothing; if equal to 1, an image must be displayed; if greater than 1, another image must be displayed

private void patient()
{
    if (OpenEventMissionData.Rows.Count != 0)
    {
        foreach (DataGridViewRow row in OpenEventMissionData.Rows)
        {
            string idevent = row.Cells[1].Value.ToString();
            string sql = "SELECT COUNT(*) FROM patient INNER JOIN event WHERE patient.ID_EVENT = " + "'" + idevent + "'" + "AND evento.EVENT_OPEN = 1;";

            MySqlConnection connection = new MySqlConnection();
            connection.ConnectionString = ConfigurationManager.ConnectionStrings["dbx"].ConnectionString;
            MySqlCommand cmd = new MySqlCommand(sql, connection);
            connection.Open();
            MySqlDataReader reader = cmd.ExecuteReader();
            if (reader.HasRows)
            {   
                DataGridViewButtonColumn patient = new DataGridViewButtonColumn();
                OpenEventMissionData.Columns.Add(new PatientColumn());
            }
        }
    }
}

I tried adding the code that told me @oldDog but the result is always 6

New editor:

actually 6 lines appear.

P粉323374878
P粉323374878

reply all(1)
P粉668146636

Your problem is that you are using HasRows. Since you are doing a SELECT COUNT(*), you will always have a row containing the count, even if the count is zero. Instead, you can use:

if (Convert.ToInt32(reader[0]) > 0)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template