UPDATE query on Access Database not working C#.NET

前端 未结 2 567
离开以前
离开以前 2021-01-19 18:45

I am working on a database management system. I have a simple task of updating user profile. I created an asp.net page with textboxes and a save button. After adding the tex

相关标签:
2条回答
  • 2021-01-19 19:10

    Add the parameter values in the same order as the parameter names appear in the UPDATE statement.

    cmd.Parameters.AddWithValue("@firstName", firstName);
    cmd.Parameters.AddWithValue("@lastName", lastName);
    cmd.Parameters.AddWithValue("@Gender", Gender);
    cmd.Parameters.AddWithValue("@Address", sAddress);
    cmd.Parameters.AddWithValue("@Telephone", sTelephone);
    cmd.Parameters.AddWithValue("@Course", sCourse);
    cmd.Parameters.AddWithValue("@Email", sEmail);
    cmd.Parameters.AddWithValue("@UserName", User.Identity.Name);
    

    OleDb with Access does not pay attention to the parameter names, only their order.

    0 讨论(0)
  • 2021-01-19 19:12

    add the parameters according to the order in the query

      string sqlQuerry = "UPDATE aspnet_Users SET firstName=@firstName, lastName=@lastName,  Gender=@Gender, Address=@Address, Telephone=@Telephone, Course=@Course, Email=@email WHERE UserName=@UserName";
    
        OleDbCommand cmd = new OleDbCommand(sqlQuerry, oleDBConn);
        cmd.CommandType = CommandType.Text;
        cmd.Parameters.AddWithValue("@firstName", firstName);
        cmd.Parameters.AddWithValue("@lastName", lastName);
        cmd.Parameters.AddWithValue("@Gender", Gender);
        cmd.Parameters.AddWithValue("@Address", sAddress);
        cmd.Parameters.AddWithValue("@Telephone", sTelephone);
        cmd.Parameters.AddWithValue("@Course", sCourse);
        cmd.Parameters.AddWithValue("@Email", sEmail);
        cmd.Parameters.AddWithValue("@UserName", User.Identity.Name);
    
    0 讨论(0)
提交回复
热议问题