私は次のことを達成しようとしています:
db からのエントリを表示する最初のグリッドがありますtable foo
。1 つを選択すると、後でクエリに使用する ID である column[0] cell[0] から回復する必要があります。このクエリは、 grid2 に からのすべての 1 対多のインスタンスを取り込みますtable bar
。しかし、ヌルポイント例外が発生し、理由がわかりません...
private void button1_Click_1(object sender, EventArgs e)
{
SqlConnection sc = new SqlConnection(@"Data Source = WARZARU-NB\SQLEXPRESS; Database = proj_1; Integrated Security = True");
dataSet.Clear();
dataAdapter.SelectCommand = new SqlCommand("select * from students WHERE id=@index", sc);
// EXCEPTION here
dataAdapter.InsertCommand.Parameters.Add("@index", SqlDbType.Int).Value = dgParent.CurrentCell.Value;
dataAdapter.Fill(dataSet, "grades");
dgChild.DataSource = dataSet.Tables["grades"];
dgParent.AutoResizeColumns();
dgParent.AutoResizeRows();
}