var sql = @"insert into tb (ceuf00,ceuf01,ceuf02,ceuf03,ceuf04) values(@ceuf00,@ceuf01,@ceuf02,@ceuf03,@ceuf04)";
OdbcConnection conn = new OdbcConnection(DBCommon.SqlConnectionString);
conn.Open();
OdbcCommand cmd = conn.CreateCommand();
cmd.Parameters.Clear();
cmd.CommandText = sql;
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add("@ceuf00", OdbcType.Char, 1).Value ="a";
cmd.Parameters.Add("@ceuf01", OdbcType.Char, 10).Value ="a";
cmd.Parameters.Add("@ceuf02", OdbcType.SmallInt).Value = 1;
cmd.Parameters.Add("@ceuf03", OdbcType.SmallInt).Value =2;
cmd.Parameters.Add("@ceuf04", OdbcType.Char, 20).Value = "a";
cmd.ExecuteNonQuery();
一执行到 cmd.ExecuteNonQuery()就报错:
ERROR [42000] [Informix][Informix ODBC Driver][Informix]A syntax error has occurred.
------解决方案--------------------
@ceuf00,@ceuf01,@ceuf02,@ceuf03,@ceuf04
-->
?,?,?,?,?
------解决方案--------------------
var sql = @"insert into tb (ceuf00,ceuf01,ceuf02,ceuf03,ceuf04) values(?,?,?,?,?)";
------解决方案--------------------
不要用"@xx"这样的参数,要用"?"
var sql = @"insert into tb (ceuf00,ceuf01,ceuf02,ceuf03,ceuf04) values(?,?,?,?,?)";
Parameter按顺序加入cmd.Parameters
cmd.Parameters.Add("@ceuf00", OdbcType.Char, 1).Value ="a";