日期:2014-05-20  浏览次数:20880 次

关于直接写SQL语句和使用Parameter参数良种方式的迷惑
///   <summary>
///   增加一条数据
///   </summary>
public   string   Add(SalesServer.Model.Inventory   model)
{
model.cInvCode=GetMaxId();
StringBuilder   strSql=new   StringBuilder();
strSql.Append( "insert   into   Inventory( ");
strSql.Append( "cInvCode,cInvName,cBarCode,cInvStd,cInvClass,cComUnit,cInvProperty1,cInvProperty2,cInvProperty3,Memo) ");
strSql.Append( "   values   ( ");
strSql.Append( "@cInvCode,@cInvName,@cBarCode,@cInvStd,@cInvClass,@cComUnit,@cInvProperty1,@cInvProperty2,@cInvProperty3,@Memo) ");
SqlParameter[]   parameters   =   {
new   SqlParameter( "@cInvCode ",   SqlDbType.Char,8),
new   SqlParameter( "@cInvName ",   SqlDbType.Char,100),
new   SqlParameter( "@cBarCode ",   SqlDbType.Char,50),
new   SqlParameter( "@cInvStd ",   SqlDbType.Char,50),
new   SqlParameter( "@cInvClass ",   SqlDbType.Char,10),
new   SqlParameter( "@cComUnit ",   SqlDbType.Char,20),
new   SqlParameter( "@cInvProperty1 ",   SqlDbType.Char,50),
new   SqlParameter( "@cInvProperty2 ",   SqlDbType.Char,50),
new   SqlParameter( "@cInvProperty3 ",   SqlDbType.Char,50),
new   SqlParameter( "@Memo ",   SqlDbType.Char,100)};
parameters[0].Value   =   model.cInvCode;
parameters[1].Value   =   model.cInvName;
parameters[2].Value   =   model.cBarCode;
parameters[3].Value   =   model.cInvStd;
parameters[4].Value   =   model.cInvClass;
parameters[5].Value   =   model.cComUnit;
parameters[6].Value   =   model.cInvProperty1;
parameters[7].Value   =   model.cInvProperty2;
parameters[8].Value   =   model.cInvProperty3;
parameters[9].Value   =   model.Memo;

DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
return   model.cInvCode;
}


------------------------------
///   <summary>
///   增加一条数据
///   </summary>
public   string   Add(SalesServer.Model.Inventory   model)
{
model.cInvCode=GetMaxId();
StringBuilder   strSql=new   StringBuilder();
strSql.Append( "insert   into   Inventory( ");
strSql.Append( "cInvCode,cInvName,cBarCode,cInvStd,cInvClass,cComUnit,cInvProperty1,cInvProperty2,cInvProperty3,Memo ");
strSql.Append( ") ");
strSql.Append( "   values   ( ");
strSql.Append( " ' "+model.cInvCode+ " ', ");
strSql.Append( " ' "+model.cInvName+ " ', ");
strSql.Append( " ' "+model.cBarCode+ " ', ");
strSql.Append( " ' "+model.cInvStd+ " ', ");
strSql.Append( " ' "+model.cInvClass+ " ', ");
strSql.Append( " ' "+model.cComUnit+ " ', ");
strSql.Append( " ' "+model.cInvProperty1+ " ', ");
strSql.Append( " ' "+model.cInvProperty2+ " ', ");
strSql.Append( " ' "+model.cInvProperty3+ " ', ");
strSql.Append( " ' "+model.Memo+ " ' ");
strSql.Append( ") ");
DbHelperSQL.ExecuteSql(strSql.ToString());