1. Parametric notation of like in fuzzy query
String keyword= "value"; To blur a matching value
Error Demonstration:
SQL: string strsql= "select * from [Table] where [Field] like% @Field%";
Parameter: system.data.sqlclient.sqlparameter[] parms = new[] {
New System.Data.SqlClient.SqlParameter ("@Field", system.data.sqldbtype.varchar,400)
};
Parms[0]. Value = KeyWord;
output: the arguments that are output by ADO SQL statement or the literal select * from [Table] where [Field] like% @Field% SQL statement error
Solution (1):
sql: string strsql= "select * from [Table] where [Field] like '% ' +@Field+ '% ' "
This way, ADO can input the parameters correctly.
Solution (2):
sql: string strsql= "select * from [Table] where [Field] like @Field";
Parameter: system.data.sqlclient.sqlparameter[] parms = new[] {
New System.Data.SqlClient.SqlParameter ("@Field", system.data.sqldbtype.varchar,400)
};
Parms[0]. Value = "%" +keyword +"%";
Analysis:
The like statement that we expect to finally transfer to the database should be: SELECT * FROM [Table] like [Field] like '%value% ' ;
Direct% @Field%, contaminated with ADO parameter marked @ symbol resulting in incorrect substitution of parameters;
Method A string concatenation in the SQL statement to get a value such as '%value% '; Note: The strings in the SQL statement are quoted as the starting character of the string, and the string is stitched in SQL Server with the + sign. so '%value% ' equals '% ' +value '% ',
Method Two add the fuzzy match character directly in the assignment statement;
C # Normal encounter problems "4"