char(20):存放20位,不够的将用空格补齐
nvarchar(2):最多存放20位
同时,向数据库跟新或者插入数据时,如果不想产生空格,最好设置字段varchar或者nvarchar类型:
public bool Add(Model.Model_Companey model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Companey ("); strSql.Append("C_OraName,C_Town,C_Trding,C_Postcode,C_Phone)"); strSql.Append(" values("); strSql.Append("@C_OraName,@C_Town,@C_Trding,lrtrim(@C_Postcode),lrtrim(@C_Phone))"); SqlParameter[] parameters = { new SqlParameter("@C_OraName",SqlDbType.NVarChar,50), new SqlParameter("@C_Town",SqlDbType.NVarChar,50), new SqlParameter("@C_Trding",SqlDbType.NVarChar,50), new SqlParameter("@C_Postcode",SqlDbType.NVarChar,10), new SqlParameter("@C_Phone",SqlDbType.NVarChar,20)}; parameters[0].Value = model.C_OraName; parameters[1].Value = model.C_Town; parameters[2].Value = model.C_Trding; parameters[3].Value = model.C_Postcode; parameters[4].Value = model.C_Phone; int rows = Helper.SQLHelper.ExcuteSQL(strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } }
新闻热点
疑难解答