Note that there are some explanatory texts on larger screens.

plurals
  1. POC#: DataGridView shows only one row
    text
    copied!<p>I have a problem with a datagridview in C#. I get the data via query from a mysql-database. But for some reason, only the first row from the result is displayed in the gridview. I use the following code to do this stuff:</p> <pre><code>MySqlCommand command = new MySqlCommand(query, Globals.Connection); reader = command.ExecuteReader(); while (reader.Read()) { object[] dataset = new object[7]; dataset[0] = reader["sto_name"]; dataset[1] = reader["esss"]; dataset[2] = reader["onl_name"]; dataset[3] = reader["rpc_id"]; if (reader["datum_aufstellung"].ToString() != "0") { dataset[4] = getDate(reader["datum_aufstellung"]); } else { dataset[4] = "Kein Datum gesetzt"; } if (reader["datum_abbau"].ToString() != "0") { dataset[5] = getDate(reader["datum_abbau"]); } else { dataset[5] = "Kein Datum gesetzt"; } dataset[6] = reader["id"]; dataGridView1.Rows.Add(dataset); } </code></pre> <p>It worked, a few lines of code earlier. ^^ Do you have an idea, what the problem is?</p> <p><strong>UPDATE:</strong> The content of the while loop is executed only one time. I was also wondering about that fact, before I asked my question here. But if I execute the Query in an MySQL-Client, it returns more rows than one.</p> <p><strong>UPDATE 2:</strong> I've noticed, that while the whole content of the while-loop is commented, the loop is executed exactly the same times as there are rows in the query-result. Any ideas?</p> <p><strong>UPDATE 3:</strong> It seems that everything after </p> <pre><code>dataGridView1.Rows.Add(dataset); </code></pre> <p>is not executed. Not only in the loop, but in the whole function. But why?</p> <p><strong>PROBLEM SOLVED:</strong> There was nothing wrong with the code posted here. I had an event in the rest of the code, which executed something, when a row in the dgv is entered. I suppose the loop breaked, when that happened. After removing that event, the dgv was properly filled.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload