0

我正在研究 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
4

0 回答 0