Mysql参数化update
第一次使用Mysql参数化更新、听他们说只要把@换成?就行、我换了怎么还是不行、最后执行的SQL却是这样 update table set name=?name,sex=?sex ... where id=?id
下面是代码 ...传过的参数是正确的、
public int UpdateElevator(string name,int brand,int region,int address,int group,DateTime install_data,int operated,int operation,DateTime yearly_data,int applied,int serviced,int inspected,DateTime next_data,string memo,string updated,DateTime updated_data,int id)
{
StringBuilder sbsql=new StringBuilder ();
sbsql.Append("UPDATE elevator SET ");
sbsql.Append("name=?name,");
sbsql.Append("brand_id=?brand_id,");
sbsql.Append("region_id=?region_id,");
sbsql.Append("address_id=?address_id");
sbsql.Append("group_id=?group_id,");
sbsql.Append("install_date=?install_date,");
sbsql.Append("operated_by_unit_id=?operated_by_unit_id,");
sbsql.Append("operation_state=?operation_state,");
sbsql.Append("yearly_inspect_date=?yearly_inspect_date,");
sbsql.Append("applied_by_unit_id=?applied_by_unit_id,");
sbsql.Append("serviced_by_unit_id=?serviced_by_unit_id,");
sbsql.Append("inspected_by_unit_id=?inspected_by_unit_id,");
sbsql.Append("next_inspect_date=?next_inspect_date,");
sbsql.Append("memo=?memo,");
sbsql.Append("updated_by=?updated_by,");
sbsql.Append("updated_date=?updated_date");
sbsql.Append(" where id=?id");
MySqlParameter[] parameters = {
new MySqlParameter("?name",MySqlDbType.VarChar,50),
new MySqlParameter("?brand_id",MySqlDbType.Int32,11),
new MySqlParameter("?region_id",MySqlDbType.Int32,11),
new MySqlParameter("?address_id",MySqlDbType.Int32,11),
new MySqlParameter("?group_id",MySqlDbType.Int32,11),
new MySqlParameter("?install_date",MySqlDbType.DateTime,0),
new MySqlParameter("?operated_by_unit_id",MySqlDbType.Int32,11),
new MySqlParameter("?operation_state",MySqlDbType.VarChar,50),
new MySqlParameter("?yearly_inspect_date",MySqlDbType.DateTime,0),
new MySqlParameter("?applied_by_unit_id",MySqlDbType.Int32,11),