string menuRecipe = "SELECT * FROM recipelist WHERE menu_ID = '" + menuID + "'";
MySqlCommand recipeCmd = new MySqlCommand(menuRecipe, db.mycon);
MySqlDataReader recipeDr = recipeCmd.ExecuteReader();
string[] info = new string[8];
while (recipeDr.Read())
{
info[1] = (recipeDr["recipe_ID"].ToString());
info[2] = (recipeDr["stock_ID"].ToString());
info[4] = (recipeDr["recipe_quantity"].ToString());
string stockName = "SELECT stock_name FROM stocksdb WHERE stock_ID = '" + info[2] + "'";
cmd = new MySqlCommand(stockName, db.mycon);
MySqlDataReader nameDr = cmd.ExecuteReader();
while (nameDr.Read())
{
info[3] = (nameDr["stock_name"].ToString());
}
this.recipeList.Items.Add(new ListViewItem(new string[] { info[1], info[2], info[3], info[4] }));
}
我主要想减少必须使用多个 SQL 命令字符串,尽管我不知道如何以及如何将它们隔离到各自的位置,因为有些可能会混乱。