如何调用存储过程 [英] how to call stored procedure
本文介绍了如何调用存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经编写了单个存储过程,用于插入,更新,删除和选择。我的程序是:
I have written single stored procedure for insert,update,delete and select.my procedure is:
ALTER PROCEDURE [dbo].[artdetails1]
(
@artdetailId int,
@artDescription varchar(50),
@artShortdesc varchar(50),
@artValidity varchar(50),
@artStatus varchar(50),
@StatementType varchar(50)
)
AS
BEGIN
BEGIN
IF @StatementType = 'Insert'
BEGIN
insert into artdetails(artDescription,artShortdesc,artValidity,artStatus)
values(@artDescription,@artShortdesc,@artValidity,@artStatus)
END
IF @StatementType = 'Select'
BEGIN
select * from artdetails
END
IF @StatementType = 'Update'
BEGIN
update artdetails SET
artDescription=@artDescription,artShortdesc=@artShortdesc,
artValidity=@artValidity,artStatus=@artStatus
where artdetailId= @artdetailId
END
else IF @StatementType = 'Delete'
BEGIN
Update artist SET @artStatus= 'not available';
END
end
end
但我很困惑如何检查C#代码中的语句类型并调用此过程。请使用help。我是sql的新手。
But i am confused how can i check the statement type in C# code and call this procedure.Please help.I am new to sql.
推荐答案
试试这样:
Try like this:
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "artdetails1";
cmd.Parameters.Add(new SqlParameter("@parametername", SqlDbType.VarChar, 50));
cmd.Parameters["@StatementType "].Value = "Insert";//query type
这篇关于如何调用存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文