【发布时间】:2018-02-23 17:30:19
【问题描述】:
我从来没有在存储过程方面遇到过这么大的麻烦。我使用 C#/ADO.NET 如下:
SqlConnection gconn = new SqlConnection(connection);
SqlCommand cmd = new SqlCommand("AddCustomerComments", gconn);
SqlParameter param = new SqlParameter("@surveyId",
SqlDbType.UniqueIdentifier, 250);
param.Value = SurveyId;
cmd.Parameters.Add(param);
从头到尾遍历所有值,一切都加起来并成立。我得到的错误是没有提供@surveyId。但它就在那里。
这是存储过程:
ALTER proc [dbo].[AddCustomerComments]
-- Add the parameters for the stored procedure here
@surveyId uniqueidentifier,
@comment varchar(250)
AS
-- Insert statements for procedure here
insert into SurveyAddendums (SurveyId, CustomerComment, RCFollowUp, RCViewed)
values (@surveyId, @comment, 0, 0);
唯一可能影响这一点的其他因素是SurveyId 是一个Guid。
为什么会出现这个错误?
【问题讨论】:
-
你需要设置
cmd.CommandType = CommandType.StoredProcedure -
是的,在我发布问题后才看到它。呜呜
-
错误信息不是很清楚...
-
@Matt SQL 和 Web 开发是编程中最“令人欣慰”的两个领域……在大学里,我下定决心要像瘟疫一样避开这两个领域。 ..但后来,我被录用了。 :-)
标签: c# sql-server stored-procedures ado.net