VisualStudioのWindowsFormを使用しています。
Form1で全生徒の登録情報一覧をDataGridViewで表示しています。
それぞれの生徒情報の右端には「編集ボタン」があり、押すと編集画面Form2へ遷移します。
Form1
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { DataGridView dgv = (DataGridView)sender; //編集ボタンを押したときの処理 if (dgv.Columns[e.ColumnIndex].Name == "編集") { this.Hide(); //編集ボタンを押した行データを渡す Form2 form2 = new Form2(dgv.Rows[e.RowIndex]); form2.Show(); } }
Form2
//削除ボタン押下時 private void DeleteBt_Click(object sender, EventArgs e) { // 接続文字列の取得 var connectionString = ConfigurationManager.ConnectionStrings["sqlsvr"].ConnectionString; // データベース接続の準備 using (var connection = new SqlConnection(connectionString)) using (var command = connection.CreateCommand()) { try { // データベースの接続開始 connection.Open(); // SQLの準備 command.CommandText = @"DELETE MEMBER_MASTER WHERE" ; // SQLの実行 command.ExecuteNonQuery(); } finally { // データベースの接続終了 connection.Close(); }
編集ボタンを押した生徒情報のレコードを削除するには
@"DELETE MEMBER_MASTER WHERE"の部分をどう書けばよいですか?
回答1件
あなたの回答
tips
プレビュー