0

別の場所に次のコードを作成しましたForm

フォーム2

private DataTable dataTable;

internal void ReadTable(ref DataTable dt)
{
   dataTable = dt;
}

private void button1_Click(object sender, EventArgs e)
{
   DataRow dataRow = dataTable.NewRow();
   foreach (ListViewItem item in listView1.Items)
   {
      dataRow[item.SubItems[1].Text] = item.SubItems[item.SubItems.Count - 1].Text;
   }
   dataTable.Rows.Add(dataRow);
}

フォーム1

private void button1_Click(object sender, EventArgs e)
{
   using (Form2 form = new Form2())
   {
      form.ReadTable(ref dataTable);
      form.ShowDialog();

      using (OleDbConnection oledbConnection = new OleDbConnection(connection))
      {
         oledbConnection.Open();
         string query = "SELECT * FROM Student";
         using (OleDbCommand oledbCommand = new OleDbCommand(query, oledbConnection))
         {
            using (OleDbDataAdapter oledbDataAdapter = new OleDbDataAdapter(oledbCommand))
            {
               using (OleDbCommandBuilder oledbCommandBuilder = new OleDbCommandBuilder(oledbDataAdapter))
               {
                  oledbDataAdapter.DeleteCommand = oledbCommandBuilder.GetDeleteCommand(true);
                  oledbDataAdapter.InsertCommand = oledbCommandBuilder.GetInsertCommand(true);
                  oledbDataAdapter.UpdateCommand = oledbCommandBuilder.GetUpdateCommand(true);
                  oledbDataAdapter.Update(dataTable);
                }
             }
          }
          oledbConnection.Close();
       }
   }
}

INSERT INTO ステートメントで構文エラーが発生するのはなぜですか?

4

1 に答える 1