大家好,我在INSERT INTO语句中收到语法错误(0x80040E14) [英] Hey guys im getting a Syntax error in INSERT INTO statement(0x80040E14)
本文介绍了大家好,我在INSERT INTO语句中收到语法错误(0x80040E14)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
private void button1_Click(object sender, EventArgs e)
{
//int iNum = Convert.ToInt32(numericUpDown1.Value);
string sName = textBox1.Text;
string connetionString = null;
OleDbConnection conn;
OleDbDataAdapter ole = new OleDbDataAdapter();
string sql = null;
connetionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Users\\Thabiso\\Documents\\Visual Studio 2013\\Projects\\mdb\\1888.mdb";
conn = new OleDbConnection(connetionString);
sql = "INSERT INTO Cars(Desc) VALUES(" + "''" + sName + "'') ";
//OleDbCommand command = new OleDbCommand("INSERT INTO FND(userName, userNumber) VALUES(''" + txtName.Text + "'',''" + numericUpDown1.Value + "'') ");
try
{
conn.Open();
ole.InsertCommand = new OleDbCommand(sql, conn);
ole.InsertCommand.CommandType.ToString();
ole.InsertCommand.ExecuteNonQuery();
conn.Close();
MessageBox.Show("done");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
推荐答案
sql = "INSERT INTO Cars ([Desc]) VALUES('" + sName + "') ";
列名"Desc"是一个错误的选择:DESC是大多数(甚至是全部!)SQL方言中的关键字("order by column1 desc").使用MS SQL Server或MS Access,可以将其放在方括号[]中使用.
还要注意,使用此创建查询的简单版本,名称中不得包含''
字符.更好地更改为参数化查询.
The column name "Desc" is a bad selection: DESC is a keyword in most (or even all!) sql dialects ("order by column1 desc"). With MS SQL Server or MS Access, you can use it when you put it in square brackets [].
Also note the the name must not contain a ''
character with this simple version of creating the query. Better change to parameterized queries.
这篇关于大家好,我在INSERT INTO语句中收到语法错误(0x80040E14)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文