我需要调用此存储过程,但是当我将它带入.dbml时,正在转换为结果为ISingleResult。我不确定如何使用所有参数正确调用它。这是我当前的代码但是当我“返回结果”说“无效的表达式术语”返回“”时出现错误。“任何帮助都表示赞赏。谢谢。
public static int CreateNewTransferee(CreateTransferee model)
{
using (var db = new NJB.NJBDataContext())
{
var result = db.SP_AddTransferee(
model.TransferEffectiveDate,
model.TransfereeName,
model.TransfereeNoticeAddressLine1,
model.TransfereeNoticeAddressLine2,
model.TransfereeNoticeCity,
model.TransfereeNoticeState,
model.TransfereeNoticeZip,
model.TransfereeNoticePhone,
model.TransfereePaymentAddressLine1,
model.TransfereePaymentAddressLine2,
model.TransfereePaymentCity,
model.TransfereePaymentState,
model.TransfereePaymentZip,
model.TransfereePaymentPhone,
return (int) result.ReturnValue;
}
}
更新:这是SP:
ALTER PROCEDURE [dbo].[SP_AddTransferee]
-- Add the parameters for the stored procedure here
@TransferEffectiveDate datetime,
@TransfereeName varchar(50),
@TransfereeNoticeAddressLine1 varchar(50),
@TransfereeNoticeAddressLine2 varchar(50),
@TransfereeNoticeCity varchar(50),
@TransfereeNoticeState varchar(2),
@TransfereeNoticeZip varchar(12),
@TransfereeNoticePhone varchar(50),
@TransfereePaymentAddressLine1 varchar(50),
@TransfereePaymentAddressLine2 varchar(50),
@TransfereePaymentCity varchar(50),
@TransfereePaymentState varchar(50),
@TransfereePaymentZip varchar(50),
@TransfereePaymentPhone varchar(50)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
INSERT INTO TransfereeList
VALUES (@TransferEffectiveDate, @TransfereeName, @TransfereeNoticeAddressLine1, @TransfereeNoticeAddressLine2,
@TransfereeNoticeCity, @TransfereeNoticeState, @TransfereeNoticeZip, @TransfereeNoticePhone,
@TransfereePaymentAddressLine1, @TransfereePaymentAddressLine2,
@TransfereePaymentCity, @TransfereePaymentState, @TransfereePaymentZip, @TransfereePaymentPhone);
SELECT SCOPE_IDENTITY();
END
答案 0 :(得分:4)
你错过了一个密切的分号和分号。
public static int CreateNewTransferee(CreateTransferee model)
{
using (var db = new NJB.NJBDataContext())
{
var result = db.SP_AddTransferee(
model.TransferEffectiveDate,
model.TransfereeName,
model.TransfereeNoticeAddressLine1,
model.TransfereeNoticeAddressLine2,
model.TransfereeNoticeCity,
model.TransfereeNoticeState,
model.TransfereeNoticeZip,
model.TransfereeNoticePhone,
model.TransfereePaymentAddressLine1,
model.TransfereePaymentAddressLine2,
model.TransfereePaymentCity,
model.TransfereePaymentState,
model.TransfereePaymentZip,
model.TransfereePaymentPhone);
// ^^ right here
return (int) result.ReturnValue;
}
}
答案 1 :(得分:0)
您可以尝试使用result.First()来获取整数。
答案 2 :(得分:0)
你的代码似乎不完整...... ???如果正确的话就这样做..
public static int CreateNewTransferee(CreateTransferee model)
{
var result;
using (var db = new NJB.NJBDataContext())
{
result = db.SP_AddTransferee(
model.TransferEffectiveDate,
model.TransfereeName,
model.TransfereeNoticeAddressLine1,
model.TransfereeNoticeAddressLine2,
model.TransfereeNoticeCity,
model.TransfereeNoticeState,
model.TransfereeNoticeZip,
model.TransfereeNoticePhone,
model.TransfereePaymentAddressLine1,
model.TransfereePaymentAddressLine2,
model.TransfereePaymentCity,
model.TransfereePaymentState,
model.TransfereePaymentZip,
model.TransfereePaymentPhone,
}
return result;
}