我正在研究ASP.NET MVC项目。这是我的代码:
orderData_Entities ordertable = new orderData_Entities();
DataTable upCSV = (DataTable)TempData["UploadedCSV"];
if (isHeaderAccepted)
{
string[] data = null;
int i = 1;
foreach (DataRow dr in upCSV.Rows)
{
ObjectParameter getemail = new ObjectParameter("email", dr["email"].ToString());
ObjectParameter getpassword = new ObjectParameter("password", dr["password"].ToString());
ObjectParameter getMobile = new ObjectParameter("Mobile", dr["Mobile"].ToString());
var results = ordertable.usp_AppUpdateUserData(idSubAccount,idcategory, getemail.Value.ToString(), getpassword.Value.ToString(), getMobile.Value.ToString());
ordertable.SaveChanges();
i++;
}
}
return RedirectToAction("Index", "BulkUpload");
这里我循环遍历所有行并将结果更新到我的表。目前正在发生的事情是,如果我有三行电子邮件,密码和移动,它将逐个循环遍历所有这三行,我可以在调试模式下看到结果,但在更新到我的表时,它正在更新最后一行结果所有三行。
那么有人能告诉我我在这里做了什么错误吗?
更新: 我的存储过程如下:
ALTER PROCEDURE [dbo].[usp_AppUpdateUserData]
@idSubAccount int = 0,
@idcategory int = 0,
@email nvarchar(100) =0,
@password nvarchar(50) = 0,
@Mobile nvarchar(50) = 0,
AS
BEGIN
Begin
Update tblCustomer
Set
email = @email, password = @password, mobileNo = @Mobile,
where idSubAccount = @idSubAccount and idCategory = @idcategory
END
End
GO