关于SqlParameter的问题 C#
经常写数据访问层的时候,会写这些代码:
string sql = @"UPDATE dbo.Table1
SET ProductID = @ProductID ,
YearNum = @YearNum ,
Batch = @newBatch
WHERE BatchID = @originalBatch ";
SqlParameter[] parameters = { new SqlParameter("@ProductID", productID),
new SqlParameter("@YearNum", year),
new SqlParameter("@newBatch", newBatch),
new SqlParameter("@originalBatch", originalBatch) };
代码中的 year 是DateTime类的,newBatch是字符串的,
如果不用 SqlParameter的话, 手写sql语句的时候,都要给 日期和字符串加上 ' ' 两个冒号,如:
string sql = @"UPDATE dbo.Table1
SET YearNum = '2015-01-01'; ,
Batch = 'a2015b1'
我很好奇想知道, SqlCommand 是怎么根据SqlParameter去生产一段完整的sql命令的