错误信息是: System.Data.OleDb.OleDbException:Insert into 语句的语法错误. at System.Data.OleDb.Command.ExecteCommandTextErrorHanding(Int 32 hr) at System.Data.OleDb.Command.ExecteCommandTextForSingleResult(tagDBPARAMS dbParams,Object& executeResult) at System.Data.OleDb.Command.ExecteCommandText.....
private void add_Click(object sender, System.EventArgs e)
{
a=this.tbdep.Text.Replace("'","''");
b= this.nametb.Text.Replace("'","''");
c=this.iptb.Text.Replace("'","''");
d=this.infoli.Text.Replace("'","''");
if(b=="" ¦ ¦c=="" ¦ ¦d=="" ¦ ¦a=="")
{MessageBox.Show("请检查,数据没填完整!");}
else
{
str="INSERT INTO wcb(dep,names,ip,info) VALUES ( '"+a+" ', '"+b+" ', '"+c+" ', '"+d+" ')";
MessageBox.Show("增加数据成功!"+str.ToString());}
jilu=0;
}
System.Data.OleDb.OleDbException:Insert into 语句的语法错误.
at System.Data.OleDb.Command.ExecteCommandTextErrorHanding(Int 32 hr)
at System.Data.OleDb.Command.ExecteCommandTextForSingleResult(tagDBPARAMS dbParams,Object& executeResult)
at System.Data.OleDb.Command.ExecteCommandText.....
你可以在access中建立一个sql查询,类似sqlserver2000的查询分析器,来帮助你分析sql语法错误!
{
a=this.tbdep.Text.Replace(" '"," ' '");
b= this.nametb.Text.Replace(" '"," ' '");
c=this.iptb.Text.Replace(" '"," ' '");
d=this.infoli.Text.Replace(" '"," ' '");
if(b=="" ¦ ¦c=="" ¦ ¦d=="" ¦ ¦a=="")
{MessageBox.Show("请检查,数据没填完整!!");}
else
{
str= "INSERT INTO wcb(dep,names,ip,info)VALUES( '" + a + "', '" + b + "', '" + c + "', '" + d + "')";
MessageBox.Show("增加数据成功!"+str.ToString());}
jilu=0;
}应当就好用了试一试!
'" + a + " ' 右边是不是多了一个空格?
或者用跟踪器!
我直接加入SQL语句都不行,还是说语法有错!
可以从数据库中读出数据显示出来,就是没法向其中添加数据\删除和修改数据!
到数据库里操作下。
^
”info)VALUES“我不知你这里有没有空格,还是Copy上来的时候才没有空格,这里应该有空格
如果这样写应该是不会有错的:
str="INSERT INTO wcb(dep,names,ip,info) VALUES( '"+a+"', '"+b+"', '"+c+"', '"+d+"')";
str="INSERT INTO wcb(dep,names,ip,info)VALUES( '"+a+" ', '"+b+" ', '"+c+" ', '"+d+" ') as temp";
就okey了。
SQL 对 插入的直具有自动转换功能 比如 你能在SQL里字段类型为 INT 的列里插入 ‘01’但在ACCESS里是报错误的