如果要避免重复,可以继续使用
DECLARE变量并一次设置其值:
var sqlReview = "DECLARE @UserID AS Int = ?, @PgID AS Int = ?, @Rating AS TinyInt = ?;"sqlReview += "DELETe FROM PGrating WHERe (UserID = @UserID) AND (PgID = @PgID);"sqlReview += "INSERT INTO PGrating (InsertDate, PgID, UserID, Rating) VALUES (GETDATE(), @PgID, @UserID, @Rating);"
以上假设SQL Server 2008或更高版本。在较低版本上,您需要单独的一行来分配:
var sqlReview = "DECLARE @UserID AS Int, @PgID AS Int, @Rating AS TinyInt;"sqlReview += "SELECt @UserID = ?, @PgID = ?, @Rating = ?;"sqlReview += "DELETE FROM PGrating WHERe (UserID = @UserID) AND (PgID = @PgID);"sqlReview += "INSERT INTO PGrating (InsertDate, PgID, UserID, Rating) VALUES (GETDATE(), @PgID, @UserID, @Rating);"
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)