我正在尝试保存syncfusion编辑表单中的数据我真的不知道我做错了什么,或者为什么我得到这个错误。
private async Task OrderLineSave()
{
await CustomerOrderService.CustomerOrderInsert(addeditOrderLine.OrderProductID = ProductID,
addeditOrderLine.OrderCustomerName,
addeditOrderLine.OrderCustomerPhoneNumber,
addeditOrderLine.OrderDeliveryAddress,
addeditOrderLine.OrderInscription,
addeditOrderLine.OrderInstruction,
addeditOrderLine.OrderDeliveryDate,
addeditOrderLine.OrderPickupTime,
addeditOrderLine.OrderRecipient,
addeditOrderLine.OrderFlavor);
}
下面是我的service class
public async Task<bool> CustomerOrderInsert(CustomerOrder customerorder)
{
using (var conn = new SqlConnection(_configuration.Value))
{
var parameters = new DynamicParameters();
parameters.Add("OrderProductID", customerorder.OrderProductID, DbType.Int32);
parameters.Add("OrderCustomerName", customerorder.OrderCustomerName, DbType.String);
parameters.Add("OrderCustomerPhoneNumber", customerorder.OrderCustomerPhoneNumber, DbType.String);
parameters.Add("OrderDeliveryAddress", customerorder.OrderDeliveryAddress, DbType.String);
parameters.Add("OrderInscription", customerorder.OrderInscription, DbType.String);
parameters.Add("OrderInstruction", customerorder.OrderInstruction, DbType.String);
parameters.Add("OrderDeliveryDate", customerorder.OrderDeliveryDate, DbType.DateTime);
parameters.Add("OrderPickupTime", customerorder.OrderPickupTime, DbType.DateTime);
parameters.Add("OrderRecipient", customerorder.OrderRecipient, DbType.String);
parameters.Add("OrderFlavor", customerorder.OrderFlavor, DbType.String);
parameters.Add("OrderIsArchived", customerorder.OrderIsArchived, DbType.Boolean);
// Stored procedure method
await conn.ExecuteAsync("spCustomerOrder_Insert", parameters, commandType: CommandType.StoredProcedure);
}
return true;
}
方法期望一个参数:
public async Task<bool> CustomerOrderInsert(CustomerOrder customerorder)
// ^--------- here ----------^
它期待CustomerOrder
对象的单个实例。但是当你调用这个方法时,你提供了十个参数:
CustomerOrderService.CustomerOrderInsert(addeditOrderLine.OrderProductID = ProductID,
addeditOrderLine.OrderCustomerName,
addeditOrderLine.OrderCustomerPhoneNumber,
addeditOrderLine.OrderDeliveryAddress,
addeditOrderLine.OrderInscription,
addeditOrderLine.OrderInstruction,
addeditOrderLine.OrderDeliveryDate,
addeditOrderLine.OrderPickupTime,
addeditOrderLine.OrderRecipient,
addeditOrderLine.OrderFlavor)
从它们的名字来看,它们似乎是单独的值,但它们绝对不是单个对象。
addeditOrderLine
会是CustomerOrder
的一个实例吗?如果是,只需将其传递给方法:
CustomerOrderService.CustomerOrderInsert(addeditOrderLine)
如果没有,则需要创建CustomerOrder
的实例。最初可以像这样简单:
CustomerOrderService.CustomerOrderInsert(new CustomerOrder())
当然,这将是一个只有默认值的新实例。如果你想要将你的值添加到那个实例中,那么你必须像创建那个实例时那样做。例如,可以作为构造函数参数。或者你可以先创建一个实例,单独设置它的所有值,然后用那个实例调用方法。
最终这部分取决于你,因为我们不知道addeditOrderLine
是什么或CustomerOrder
是什么。但错误本身的根源非常简单……该方法需要一个单独的CustomerOrder
对象,而不是一堆单独的值。