这是我的 MySQL SP,用于填充具有超过 1 个结果的 asp.net4.0 gridview。但它只返回 1 行。请帮助我如何用所有结果填充gridview。谢谢大家。
CREATE DEFINER=`metro`@`localhost` PROCEDURE `p_get_plants_gridview`()
LANGUAGE SQL
NOT DETERMINISTIC
MODIFIES SQL DATA
SQL SECURITY DEFINER
COMMENT 'procedure to populate plants gridview in plants.aspx page.'
BEGIN
DECLARE noMoreRow INT DEFAULT 0;
DECLARE plantid INT UNSIGNED;
DECLARE plantname VARCHAR(100);
DECLARE plantcode VARCHAR(10);
DECLARE plantaddr1 VARCHAR(50);
DECLARE plantaddr2 VARCHAR(50);
DECLARE plantaddr3 VARCHAR(50) ;
DECLARE O_PL_CURSOR CURSOR FOR SELECT plant_id,
plant_name,
plant_code,
plant_addr1,
plant_addr2,
plant_addr3
FROM plants;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET noMoreRow = 1;
OPEN O_PL_CURSOR;
LOOPROWS: LOOP
FETCH O_PL_CURSOR INTO plantid,plantname,plantcode,plantaddr1,plantaddr2,plantaddr3;
IF noMoreRow THEN
LEAVE LOOPROWS;
END IF;
SELECT plantid,plantname,plantcode,plantaddr1,plantaddr2,plantaddr3;
END LOOP;
CLOSE O_PL_CURSOR;
END;
这是填充数据表的 ASP.net 例程:
public DataTable GetPlants_Grid()
{
MySqlConnection conn = new
MySqlConnection(Configuration.ConnectionInfo);
DataTable dt = new DataTable();
MySqlCommand cmd = new MySqlCommand("p_get_plants_gridview", conn);
cmd.CommandType = CommandType.StoredProcedure;
conn.Open();
dt.Clear();
try
{
MySqlDataAdapter da = new MySqlDataAdapter();
da.SelectCommand = cmd;
da.Fill(dt);
}
catch (MySqlException ex) { string msg = ex.Message; }
finally { conn.Close(); }
return dt;
}