今天写一个C#访问Access的程序,拼接SQL语句时一直出错,
string sql = "insert into dllinfos (dllname,dllfilename,type,functions,harm,repairmethod,issys, paths, ishorse, language, version, company) values ('" + textBox1.Text + "','" + textBox2.Text + "','" +
textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "','" +
textBox8.Text + "','" + textBox9.Text + "','" + textBox10.Text + "','" + textBox11.Text + "','" + textBox12.Text +
"');";
查了很久;
原来 language 应该是Access或一些数据库的一个保留关键字,不能直接用作字段名;
改为 mylanguage 之类即可;
修改字段名,
match也不能作为字段名;
上回有十几个字段,其中字段名包含match,不能插入,改为pmatch就可以了;下面单独做一个表验证一下此问题;
新建一个test1表,只有match字段,
insert into 看一下,出错,
然后再建一个test2表,只有一个字段pmatch,看一下可以insert into;
还有不能作为字段名的,这主要是Access,
describe,