코드의 어느 부분이 잘못되었는지 알 수 없습니다.저장 프로 시저에 매개 변수 보내기
이 내 저장 프로 시저
ALTER PROCEDURE dbo.AddNewNews
(@title nvarchar(50),
@text ntext,
@year int,
@month int,
@day int,
@id_writer int ,
@id_subject1 int,
@id_subject2 int,
@id_subject3 int,
@id_subject4 int,
@id_subject5 int)
AS
SET NOCOUNT ON
BEGIN TRANSACTION;
DECLARE @last_id_news int
BEGIN TRY
insert into news(title, text, year, month, day, id_writer)
values(@title, @text, @year, @month, @day, @id_writer)
set @last_id_news = SCOPE_IDENTITY()
if @id_subject1 is not null
begin
insert into news_subject (id_news,id_subject) values (@last_id_news,@id_subject1)
end
if @id_subject2 is not null
begin
insert into news_subject (id_news,id_subject) values (@last_id_news,@id_subject2)
end
if @id_subject3 is not null
begin
insert into news_subject (id_news,id_subject) values (@last_id_news,@id_subject3)
end
if @id_subject4 is not null
begin
insert into news_subject (id_news,id_subject) values (@last_id_news,@id_subject4)
end
if @id_subject5 is not null
begin
insert into news_subject (id_news,id_subject) values (@last_id_news,@id_subject5)
end
COMMIT TRANSACTION;
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION;
END CATCH;
RETURN
이며, 이것은 내가 내 C# 코드에서 저장 프로 시저에 매개 변수를 전송하는 방법이다 : 널 (null)이 될 수
public bool AddNewNews(News news, List<object> subject)
{
SqlParameter[] parameters = new SqlParameter[]
{
new SqlParameter ("@title", news.Id_news),
new SqlParameter ("@text", news.Text),
new SqlParameter ("@year", news.Year),
new SqlParameter ("@month", news.Month),
new SqlParameter ("@day", news.Day),
new SqlParameter ("@id_writer", news.Id_writer),
new SqlParameter ("@id_subject1", subject[0]),
new SqlParameter ("@id_subject2", subject[1]),
new SqlParameter ("@id_subject3", subject[2]),
new SqlParameter ("@id_subject4", subject[3]),
new SqlParameter ("@id_subject5", subject[4])
};
return SqlDBHelper.ExecuteNonQuery("AddNewNews", CommandType.StoredProcedure, parameters);
}
그냥 주제 [I]
그러나 저장 프로 시저로 이동하여 id_subject
이 거짓인지 또는 다른 코드 부분인지 확인하지 못합니까?
당신이 그것을 잘못에 대해 어떻게 생각 하죠? 구문 오류 또는 예외가 발생합니까? –
어떤 오류가 나타 납니까? 마지막 리턴에 중단 점을 두어 모든 매개 변수 값 –
을 볼 수 있습니다. 오류입니다. 프로 시저 또는 함수 'AddNewNews'에 제공되지 않은 '@ id_subject3'매개 변수가 필요합니다. – nimaSadeghpour