简体   繁体   English

将数据插入数据库时​​出现C#错误

[英]C# Error when Insert Data To Database

I want to insert data into a .MDB file, but I get this error: 我想将数据插入.MDB文件,但出现此错误:

错误

This is my .MDB table : 这是我的.MDB表:

我的资料库

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. 当我插入3列时,它可以工作,但是当我要插入许多列时,代码不起作用。

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. 这是我第一次使用.MDB数据库文件。

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. ODBC保留关键字只是为了澄清前面的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误-将数据插入C#中的Access数据库 - Error - Insert data into Access database in c# C#插入数据库,没有错误,数据没有插入数据库 - C# Insert into database, no error and data is not inserted into database 尝试通过C#应用程序将数据插入SQL Server数据库时出错 - Error when trying to insert data to a SQL Server database through a C# application 使用OleDbConnection将数据提交到Access数据库时,在C#中调试“ INSERT INTO语句中的语法错误” - Debug “Syntax error in INSERT INTO statement” in C# when submitting data to Access Database using OleDbConnection 数据未插入C#数据库中 - data in not insert in database in c# 使用 C# 将数据插入数据库时​​出错 - Error when inserting data into database with C# C#插入访问数据库:无错误,命令成功,但未插入数据 - C# insert into access database: no error, command succeeds, but no data inserted c# 插入数据库数据类型不匹配错误 - c# insert to database data type mismatch error 尝试以c#格式将数据插入数据库,但在按下插入按钮时收到此错误消息。 不提供参数 - Trying to insert data to database in c# forms but getting this error message when insert button is hit. Parameter not supplied 插入Access数据库时插入错误C# - Insert error C# when inserting into access database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM