0
asp.netとMySQLを使用してWebアプリケーションを開発しています。私のアプリでは、ユーザーはレシピを追加できます。それは挿入されるレコードです。私は食材をデータベースにも入力しなければなりません。私は入力要素(チェックボックスの形をしています)をキャプチャしようとしています。GetIngredientsInput()メソッドを確認してください。どのチェックボックスがチェックされているかチェックしていて、チェックされているアイテムのTEXTを保存しています。私はリストの形で入力をキャプチャしたい。 (文字列のリスト)私はStringBuilderを使ってこれをテキストエリアコントロールに割り当てました。しかし、コードは有効ではないようです。前もって感謝します。CheckBoxリストの入力をキャプチャし、テキストエリアに割り当てます。
protected void AddRecipe(object sender, EventArgs e)
{
GetIngredientsInput();
MySqlConnection con = new MySqlConnection("Server=localhost;Database=FreedomKitchen;Uid=root;Password=;");
con.Open();
String strcmd = "insert into Recipes(Recipe_ID,Food_Category,Meal_Category,Recipe_Name,All_Ingredients,Recipe_Description,Recipe_Instructions) values(@Recipe_ID,@Food_Category,@Meal_Category,@Recipe_Name,@All_Ingredients,@Recipe_Description,@Recipe_Instructions)";
MySqlCommand cmd = new MySqlCommand(strcmd, con);
MySqlCommand cmd_two = new MySqlCommand("select * from Recipes", con);
MySqlDataAdapter da = new MySqlDataAdapter();
da.SelectCommand = cmd_two;
DataSet ds = new DataSet();
da.Fill(ds, "Rows");
int row_count = ds.Tables["Rows"].Rows.Count;
r_id = row_count + 1;
cmd.Parameters.Add(new MySqlParameter("@Recipe_ID", r_id));
cmd.Parameters.Add(new MySqlParameter("@Food_Category", DropDownFoodCat.Text.ToString()));
cmd.Parameters.Add(new MySqlParameter("@Meal_Category", DropDownMealCat.Text));
cmd.Parameters.Add(new MySqlParameter("@Recipe_Name", txtRecipeName.Text));
cmd.Parameters.Add(new MySqlParameter("@All_Ingredients", txtAllIngredients.Text));
cmd.Parameters.Add(new MySqlParameter("@Recipe_Description", txtDescription.Text));
cmd.Parameters.Add(new MySqlParameter("@Recipe_Instructions", txtInstructions.Text));
cmd.ExecuteNonQuery();
con.Close();
}
public void GetIngredientsInput() {
foreach (ListItem li in CheckBoxListVeg.Items) {
if (li.Selected) {
String ing_name=li.Text.ToString();
str_ing_name.Append(ing_name);
str_ing_name.Append("\n");
txtAllIngredients.Text = ing_name = li.Text.ToString();
}
}
}
。それでもtxtAllIngredientsは空のままです。 – user6302221
私は答えを編集しました、それは動作します –