我打电话
public bool CheckIfFinished ( Guid pid, int sid )
{
// pid: guid corresponding to partner
// sid: survey id
bool finished = false;
using (SqlCommand cmd = new SqlCommand("CheckIfFinished", this._Conn))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@pid", pid);
cmd.Parameters.AddWithValue("@sid", sid);
this._Conn.Open();
using ( SqlDataReader dataReader = cmd.ExecuteReader() )
{
while (dataReader.Read())
{
finished = dataReader.GetByte(0) == 1 ? true : false;
}
}
this._Conn.Close();
}
return finished;
}
调用sproc
GO
-- Create sproc for returning whether a partner has marked their survey as finished
CREATE PROCEDURE CheckIfFinished
@pid UNIQUEIDENTIFIER,
@sid INT
AS
BEGIN
SELECT 1 FROM FinishedMappings WHERE partner_id=@pid AND survey_id=@sid
END
使用表FinishedMappings
,因为它是用
CREATE TABLE FinishedMappings (
partner_id UNIQUEIDENTIFIER,
survey_id INT,
PRIMARY KEY (partner_id,survey_id),
FOREIGN KEY (partner_id) REFERENCES Partners(id),
FOREIGN KEY (survey_id) REFERENCES Surveys(id)
);
在proc正上方。为什么我收到错误?
答案 0 :(得分:0)
如果表是使用与您正在执行sp的用户不同的用户创建的,那么可能需要一个完全限定的名称。我会先在dimasun的第一次回复中提出这个问题。
还要检查是否可以直接在SQL管理工作室中执行sp。如果这不起作用,那么您可以专注于sp
中的代码