If you are using MS SQL, download the profiler and you will see which SQL commands are generated when using parameterized queries. Here is an example (I am using Enterprise Libary 3.1, but the results are the same as SqlParameters directly) against SQL Server 2005:
string sql = "SELECT * FROM tblDomains WHERE DomainName = @DomName AND DomainID = @Did"; Database db = DatabaseFactory.CreateDatabase(); using(DbCommand cmd = db.GetSqlStringCommand(sql)) { db.AddInParameter(cmd, "DomName", DbType.String, "xxxxx.net"); db.AddInParameter(cmd, "Did", DbType.Int32, 500204); DataSet ds = db.ExecuteDataSet(cmd); }
This generates:
exec sp[underscore]executesql N'SELECT * FROM tblDomains WHERE DomainName = @DomName AND DomainID = @Did', N'@DomName nvarchar(9), @Did int', @DomName=N'xxxxx.net', @Did=500204
You can also see here, if quote symbols were passed as parameters, they are escaped accordingly:
db.AddInParameter(cmd, "DomName", DbType.String, "'xxxxx.net"); exec sp[underscore]executesql N'SELECT * FROM tblDomains WHERE DomainName = @DomName AND DomainID = @Did', N'@DomName nvarchar(10), @Did int', @DomName=N'''xxxxx.net', @Did=500204
Kev
source share