我想用C#和mysql执行多个查询,这是我的代码
MySqlConnectionStringBuilder connString = new MySqlConnectionStringBuilder();
connString.Server = "10.16.106.77";
connString.Database = "pln";
connString.UserID = "root";
connString.Password = "xxxxx";
connString.IgnorePrepare = false;
using(MySqlConnection conn = new MySqlConnection(connString.ToString())){
string cmdText = @"SELECT GROUP_CONCAT(DISTINCT CONCAT('MAX(IF(keterangan = ''',keterangan,''', talenta, NULL)) AS ', QUOTE(keterangan)) ORDER BY keterangan ASC) INTO @sql FROM `data`;
SET @sql = CONCAT('SELECT nip, nama, jabatan,`tanggal jabatan definitif`, unit, jenjang_jabatan, grade_terakhir, tanggal_grade,', @sql, ' FROM data GROUP BY nip');
PREPARE stmt FROM @sql;
EXECUTE stmt";
MySqlCommand cmd = new MySqlCommand(cmdText, conn);
cmd.Connection.Open();
using (MySqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
listBox1.Items.Add(reader.GetString("tanggal_grade"));
}
}
}
它会抛出错误:
@sql必须定义。
请帮忙吗?