资源描述:
《c#中parameter的使用(国外英语资料)》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、C#中parameter的使用Smallexperienceofpassingparametersinc#executingSQLstatementsDirectwriting:Suchas:IntId=1;StringName="lui";Thecmd.CommandText="insertintoTUserLoginvalues("+Id+","+Name+")";BecauseIdisthenumericalvalue,soatthetimeofdeliveryonlyneedtouse"+Id+"intheSQLstringcanberealized
2、,andtheNameisastring,soatthetimeofdeliveryalsoneedtoaddtoeachsideofthe"+Name+"asinglequotes(')toimplement;2,addparameterstothecommandobject:Suchas:IntId=1;StringName="lui";Thecmd.CommandText="insertintoTUserLoginvalues(@id,@name)";//theparameternamesaddedintheSQLstatementarewritten
3、directlyintheSQLstatement,regardlessoftheparametertype.SqlParameterpara=newSqlParameter("@id",sqldbtype.int,4);//generateanamefortheparametersofthe@Id,mustbeginwith@saidparameterisadded,andsetitstype,length,typelengthisthesameasthecorrespondingfieldinthedatabasePara.Value=Id;//assi
4、gnvaluestoparametersCMD.TheParameters.TheAdd(para);//mustaddparametervariablestothecommandobject.//similartoPara=newSqlParameter("@name",sqldbtype.varchar,16);Para.Value=Name;Com.TheParameters.TheAdd(para);...Thenyoucanperformthedatabaseoperation.Statement:thispostisfromhttp://www.
5、knowsky.com/339188.htmlInthispost,Iwouldliketoexpressmysinceregratitudetotheoriginalauthorofthispost.Forexample,thisisthefirsttimethatapersonhasaproblemwiththeproblemSqlParameterusageSqlParameter[]parameters={newSqlParameter("@a","a1"),newSqlParameter("@b","b1")}StringstrReturn="";
6、StringBuilderstrBulResult=newStringBuilder();Foreach(SqlParameterparameterinparameters){StrBulResult.Append(parameter.ParameterName);"Strbulresult.append(":");StrBulResult.Append(parameter.SqlValue);"Strbulresult.append("");}StrReturn=strbulresult.tostring().Statement:thisposthas
7、beenforwardedtohttp://hi.baidu.com/daxiongmao_adi/blog/item/d7ac6ccdd7534534553.htmlInthispost,Iwouldliketoexpressmysinceregratitudetotheoriginalauthorofthispost.Forexample,thisisthefirsttimethatapersonhasaproblemwiththeproblemSqlParameterusageThebasicideaofSqlinjectionis,youknow,i
8、t'sclearthattheclassicinje