#regionImplementing fuzzy queries with parameter-based SQL statements (multi-criteria queries)StringBuilder SB=NewStringBuilder ("SELECT * FROM Books"); List<string> listwheres =Newlist<string>(); List<SqlParameter> Listparams =NewList<sqlparameter>(); if(TxtBookName.Text.Trim (). Length >0) {Listwheres.add ("bookname like @bkName"); Listparams.add (NewSqlParameter ("@bkName","%"+ TxtBookName.Text.Trim () +"%")); } if(TxtPubName.Text.Trim (). Length >0) {Listwheres.add ("publishname like @pubName"); Listparams.add (NewSqlParameter ("@pubName","%"+ TxtPubName.Text.Trim () +"%")); } if(TxtPrice.Text.Trim (). Length >0) {Listwheres.add ("Price = @price"); Listparams.add (NewSqlParameter ("@price",Double. Parse (TxtPrice.Text.Trim ())); } if(Listwheres.count >0) {sb. Append ("where"); stringWheres =string. Join (" and", Listwheres.toarray ()); Sb. Append (wheres); } MessageBox.Show (sb.) ToString ()); Sqlparameter[] PMS=Listparams.toarray (); #endregion
Implementing fuzzy queries with parameter-based SQL statements (multi-criteria queries)