Skip to main content
added 6 characters in body
Source Link
bbsimonbb
  • 29.3k
  • 18
  • 92
  • 129
var bldr = new SqlBuilder( myCommand ); bldr.Append("SELECT * FROM CUSTOMERS WHERE ID = ").Value(myId, SqlDbType.Int); //or bldr.Append("SELECT * FROM CUSTOMERS WHERE NAME LIKE ").FuzzyValue(myName, SqlDbType.NVarChar); myCommand.CommandText = bldr.ToString(); 
var bldr = new SqlBuilder( myCommand ); bldr.Append("SELECT * FROM CUSTOMERS WHERE ID = ").Value(myId, SqlDbType.Int); //or bldr.Append("SELECT * FROM CUSTOMERS NAME LIKE ").FuzzyValue(myName, SqlDbType.NVarChar); myCommand.CommandText = bldr.ToString(); 
var bldr = new SqlBuilder( myCommand ); bldr.Append("SELECT * FROM CUSTOMERS WHERE ID = ").Value(myId, SqlDbType.Int); //or bldr.Append("SELECT * FROM CUSTOMERS WHERE NAME LIKE ").FuzzyValue(myName, SqlDbType.NVarChar); myCommand.CommandText = bldr.ToString(); 
added 51 characters in body
Source Link
bbsimonbb
  • 29.3k
  • 18
  • 92
  • 129

The following class wraps the stringbuilder that you will commonly use for building SQL requests, and hides the creation of parameters. It lets you write paramaterized queries without ever having to create a parameter, so you can concentrate on the SQL. It lets you writeYour code will look like this...

var bldr = new SqlBuilder( myCommand ); bldr.Append("SELECT * FROM CUSTOMERS WHERE ID = ").Value(myId, SqlDbType.Int); //or bldr.Append("SELECT * FROM CUSTOMERS NAME LIKE ").FuzzyValue(myName, SqlDbType.NVarChar); myCommand.CommandText = bldr.ToString(); 

The following class wraps the stringbuilder that you will commonly use for building SQL requests, and hides the creation of parameters, so you can concentrate on the SQL. It lets you write code like...

var bldr = new SqlBuilder( myCommand ); bldr.Append("SELECT * FROM CUSTOMERS WHERE ID = ").Value(myId, SqlDbType.Int); //or bldr.Append("SELECT * FROM CUSTOMERS NAME LIKE ").FuzzyValue(myName, SqlDbType.NVarChar); 

The following class wraps the stringbuilder that you will commonly use for building SQL requests. It lets you write paramaterized queries without ever having to create a parameter, so you can concentrate on the SQL. Your code will look like this...

var bldr = new SqlBuilder( myCommand ); bldr.Append("SELECT * FROM CUSTOMERS WHERE ID = ").Value(myId, SqlDbType.Int); //or bldr.Append("SELECT * FROM CUSTOMERS NAME LIKE ").FuzzyValue(myName, SqlDbType.NVarChar); myCommand.CommandText = bldr.ToString(); 
added 48 characters in body
Source Link
bbsimonbb
  • 29.3k
  • 18
  • 92
  • 129

Code readability, I hope you agree, is greatly improved, and the output is a proper parameterized query.

Code readability, I hope you agree, is greatly improved.

Code readability, I hope you agree, is greatly improved, and the output is a proper parameterized query.

Source Link
bbsimonbb
  • 29.3k
  • 18
  • 92
  • 129
Loading