I am adding columns dynamically from rows with the following prepared statement in mysql.
SET @sql = null;
SELECT
GROUP_CONCAT(DISTINCT
CONCAT(
'SUM(IF(PC.id_competencia='
,PC.id_competencia
,',PC.puntaje,0) ) AS Puntaje_'
,PC.id_competencia
)
) into @sql
FROM
persona PE
Join personacomp PC on PE.id_persona=PC.id_persona
where pc.id_categoria=1;
select @sql;
SET @sql =CONCAT(
'SELECT concat(PE.nombre," ",PE.apellidoPaterno) as Nombree,',@sql,
', SUM(PC.puntaje) AS \'Puntaje Total\' from persona PE
join personacomp PC on PE.id_persona=PC.id_persona
where PC.id_categoria=1
Group By Nombree');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
This is the table that I generate:
My question would be how can I execute this prepared statement to fill a DataGrid with the generated table?
EDIT ##
my connection is with an instance MysqlConnection, as follows:
string conexString = "SERVER=localhost;DATABASE=pyc;UID=root;PASSWORD=****";
MySqlConnection conex = new MySqlConnection(conexString);