使用C#创建存储过程

时间:2014-01-03 17:17:05

标签: c# stored-procedures

我想定义一个存储过程,其中有2个表插入第一个表并更新第二个表。第一个表包含PostID和PersonID,第二个表包含postID和Counter。你能帮我纠正一下吗?我知道这不对。

com.CommandText = @"CREATE PROCEDURE dbo.Facebook @PostID int,@PerosnalID int, 
                   BEGIN 
                         INSERT dbo.Like (PostID) VALUES (@PersonalID), 
                         UPDATE dbo.Counter (Counter) 
                            SET PostID = @value1 
                          WHERE Counter = Sum @PersonalID 
                   END";

1 个答案:

答案 0 :(得分:0)

让我们开始并修复过程语法:

com.CommandText = "CREATE PROCEDURE dbo.Facebook( @PostID int,@PersonalID int) AS "+
                  " INSERT dbo.[Like] (PostID) VALUES (@PersonalID); " +
                  " UPDATE C SET Counter = (SELECT COUNT(*) FROM dbo.[Like] WHERE PostId = @PersonalID)" +
                  " FROM dbo.Counter AS C " +
                  " WHERE C.PostID = @PersonalID  ";