I would like to improve the function below without calling twice InserisciRigaNote
.
Before I fill my dictionary
. When I compare idNota
with the current database id
I check if it is equal or not, if different means that the dictionary
is filled and I can proceed with the insertion of the row in DataGridView
I have a query that return this output:
I have to fill a DataGridView
in that way
string query = ""; // Query MySQL
using (MySqlDataReader reader = db.ExecuteReader(query))
{
if (reader.HasRows)
{
int idNota = 1;
var note = new Dictionary<string, string>();
while (reader.Read())
{
if (idNota != Convert.ToInt32(reader["id_nota_lavaggio"]))
{
InserisciRigaNote(note, idNota); // Function that insert row in the DataGridView
idNota = Convert.ToInt32(reader["id_nota_lavaggio"]);
note.Clear();
}
// Create a dictionary made by a language key and a description
note[reader["id_lingua"].ToString()] = reader["descrizione_nota_lavaggio"].ToString();
}
if (note.Count > 0) // If there is something in the dictionary
{
InserisciRigaNote(note, idNota);
note.Clear();
}
}
}
N.B. I did not use Pivot to make the query because I need it's all completely dynamic