C# - 对象引用未设置为INSERT中对象的实例

时间:2016-05-24 02:27:10

标签: c# database

我不知道发生了什么,但代码之前的工作完美无缺。我甚至备份了,但仍然会出现错误。

这是我保存按钮的代码。

private void btnSaveData_Click(object sender, EventArgs e)
{
    connection.Open();
    OleDbCommand connect = new OleDbCommand();
    connect.Connection = connection;
    connect.CommandText = @"INSERT into [Household Data] 
             (EID,PENRO,CENRO,[Name of Protected Area],Province,Municipality,
              Barangay, [Date Accomplished], [Date of Occupancy], [Household Tag No],
              [Proofs of Occupancy], [Area of Homelot (ha)], [Location (GPS Reading1)],
              [Area of Farmlot (ha)], [Location (GPS Reading2)], [Area of Other Use])
         VALUES ('" + txtEID.Text + "','" + txtPENRO.Text + "','" + txtCENRO.Text
                 + "', ,'" + txtNameArea.SelectedItem.ToString() + "','"
                 + txtProvince.SelectedItem.ToString() + "', '"
                 + txtMunicipality.SelectedItem.ToString().Trim() + "', '"
                 + txtBarangay.Text + "', '" + pickerDateAccomplished.Text
                 + "', '" + pickerOccupation.Text + "' , '" + txtHouseholdNo.Text
                 + "' , '" + txtProofsOccupation.Text + "' , '" + txtHomelot.Text
                 + "' , '" + txtGPS1.Text + "' , '" + txtFarmlot.Text + "' , '"
                 + txtGPS2.Text + "' , '" + txtAreaOthers.Text + "');";

        connect.ExecuteNonQuery();
        MessageBox.Show("Data Saved into MS ACCESS");
        ClearTextBoxes();
        connection.Close();
    }

但是当我尝试从一开始就手动完成它。它将起作用,数据将被保存,在输入多少后,错误将再次出现。

请帮助错误出现在" INSERT"

0 个答案:

没有答案