【发布时间】:2012-11-30 01:32:02
【问题描述】:
为什么会出现这个错误?错误信息是:Syntax error in INSERT INTO statement.
我想向我的数据库中添加一条记录,但它不起作用。 问题出在哪里?
代码是:
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
OleDbDataAdapter DbDataAdabter = new OleDbDataAdapter();
DbDataAdabter.SelectCommand = new OleDbCommand("SELECT * FROM [Phone-Book]", connection);
OleDbCommandBuilder cb = new OleDbCommandBuilder(DbDataAdabter);
connection.Open();
DataRow dataRow = myDataset.Tables["salam"].NewRow();
dataRow[1] = textBox2.Text;
dataRow[2] = textBox3.Text;
dataRow[3] = textBox4.Text;
dataRow[4] = textBox5.Text;
dataRow.EndEdit();
myDataset.Tables["salam"].Rows.Add(dataRow);
DbDataAdabter.Update(myDataset , "salam");
connection.Close();
connection.Dispose();
}
}
【问题讨论】:
-
您需要在 DataAdapter 中向我们展示对
INSERT语句的查询。 -
你能告诉我你的表结构吗?
-
抱歉耽搁了。 @sajanyamaha: dataRow[0] : 自动编号 dataRow[1] :text [2]: text [3]: number [4]:number
-
@KuyaJohn :我的代码没有插入语句。我必须这样做吗?我的数据库表有 5 列 [number] , [namec] , [gushi] , [tell] , [code] 它们的数据类型在上面的注释中