private void Add2_Click(object sender, EventArgs e)//新規追加 本棚の場所 { string addquery; string IDquery; string addtitle; int ID; SQLiteDataReader reader = null; //リフレッシュ用 addtitle = Textbox2.Text; //textboxから追加したい文言の取得 DialogResult res = MessageBox.Show(addtitle + " を登録しますか?", //確認処理 "追加確認", MessageBoxButtons.YesNo); if (res == DialogResult.Yes) { IDquery = "select max(bookShelf_ID) from t_house_shelf where place_ID = " + beforeListView1ID;//現在のID最大値取得sql //追加作業部分 if (SQLiteConnect.checkRecord2("t_house_shelf", "place_ID", beforeListView1ID) == 0)//レコードない時の処理 { ID = 1; } else { SQLiteConnect.Excute(IDquery, ref reader); reader.Read(); ID = int.Parse(reader["max(bookShelf_ID)"].ToString()) + 1; //追加用の新規ID生成 reader.Close(); SQLiteConnect.conn.Close(); } addquery = "INSERT into t_house_shelf(place_ID,bookShelf_ID,shelf_name)VALUES(" + beforeListView1ID + "," + ID + "," + "'" + Textbox2.Text + "')"; //追加用sql組み立て SQLiteConnect.Excute(addquery); //登録作業 Listview2.Items.Clear(); SQLiteConnect.lording(ref Listview2, "select bookShelf_ID,shelf_name from t_house_shelf where place_ID = " + beforeListView1ID, "bookShelf_ID", "shelf_name"); } }