[英]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.