简体   繁体   中英

C# Error when Insert Data To Database

I want to insert data into a .MDB file, but I get this error:

错误

This is my .MDB table :

我的资料库

This my code :

private void btn_Save_Click(object sender, EventArgs e)
{
    try
    {
        string sql = string.Format("insert into Input (Tgl, p, l, t, Shift, Grup, Good Board, Reject Board, Wood, Emulsion, Glue, NH4CL, Urea, Rambung, Meranti, Veneer, Potongan, Lamtoro, Log End, Saw Dust, Sembarang, MDF Screen Dust, Kemiri, Slab Durian, Flakes) VALUES ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}','{20}','{21}','{22}','{23}','{24}')", dateTimePicker1.Text, txt_p.Text, txt_l.Text, txt_t.Text, txt_Shift, txt_Group, txt_GoodBoard.Text, txt_RejectBoard.Text, txt_Wood.Text, txt_Emulsi.Text, txt_Glue.Text, txt_NH4CL.Text, txt_Urea.Text, txt_Rambung.Text, txt_Meranti.Text, txt_Veneer.Text, txt_Potongan.Text, txt_Lamtoro.Text, txt_LogEnd.Text, txt_SawDust.Text, txt_Sembarang.Text, txt_MDFScreenDust.Text, txt_Kemiri.Text, txt_SlabDurian.Text, txt_Flakes.Text);

        OleDbConnection conn = new OleDbConnection(koneksi);
        conn.Open();

        OleDbCommand cmd = new OleDbCommand(sql, conn);
        cmd.ExecuteNonQuery();

        conn.Close();
        MessageBox.Show("Data Page 1");
    }
    catch (OleDbException salah)
    {
        MessageBox.Show(salah.ToString());
    }
}

When I insert 3 columns, it works, but when I want to insert many columns, the code does not work.

I have no idea what could be wrong with my statement. I already searched many questions similar, but still have no idea what's wrong with me code. Can anybody help me solve this problem? Or does anyone have suggestions for fixing my code? This is my 1st time I use a .MDB database file.

Thanks

尝试将您的insert into Input ...替换insert into Input ... INSERT INTO [Input] ...

I think the error is the reserved word 'input' should rename it. ODBC Reserved Keywords Just to clarify the previous answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM