Mysql参数化update
第一次使用Mysql参数化更新、听他们说只要把@换成?就行、我换了怎么还是不行、最后执行的SQL却是这样 update table set name=?name,sex=?sex ... where id=?id
下面是代码 ...传过的参数是正确的、
Mmysql asp.net update
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),
new MySqlParameter("?serviced_by_unit_id",MySqlDbType.Int32,11),
new MySqlParameter("?inspected_by_unit_id",MySqlDbType.Int32,11),
new MySqlParameter("?next_inspect_date",MySqlDbType.DateTime,0),
new MySqlParameter("?memo",MySqlDbType.VarChar,255),
new MySqlParameter("?updated_by",MySqlDbType.VarChar,50),
new MySqlParameter("?updated_date",MySqlDbType.DateTime,0),
new MySqlParameter("?id",MySqlDbType.Int32,11)};
parameters[0].Value = name;
parameters[1].Value = brand;
parameters[2].Value = region;
parameters[3].Value = address;
parameters[4].Value = group;
parameters[5].Value = install_data;
parameters[6].Value = operated;
parameters[7].Value = operation;
parameters[8].Value = yearly_data;
parameters[9].Value = applied;
parameters[10].Value = serviced;
parameters[11].Value = inspected;
parameters[12].Value = next_data;
parameters[13].Value = memo;
parameters[14].Value = updated;
parameters[15].Value = updated_data;
parameters[16].Value = id;
int i=MysqlHelper.GetCountP(sbsql.ToString(),parameters);
if (i > 0)
{
return 1;
}
else {
return 0;
}
}