How to use TableAdapter to update a row into SQL database (C#)
<p>Here is my code:</p>

<pre><code>using (var conn = new SqlConnection(sqlConnectionString))
{
    conn.Open();
    using (var trans = conn.BeginTransaction())
    {
        if (SaveChanges(conn, trans, user))
        {
            trans.Commit();
        }
        else
        {
            trans.Rollback();
        }            
    }
}

private bool SaveChanges(SqlConnection sqlConnection, SqlTransaction transaction, User aUser)
{
    try
    {
        dt = new UserInformationDataSet.UserInformationDataTable();
        using (var adpt = new UserInformationTableAdapter())
        {
            adpt.Connection = sqlConnection;
            adpt.Transaction = transaction;

            UserInformationDataSet.UserInformationRow row = dt.NewUserInformationRow();
            row.Name = aUser.Name;
            row.Email = aUser.Email;
            row.Position = aUser.Position;
            row.IDNumber = aUser.IDNumber;
            row.Sex = aUser.IsMale;
            row.CreateDate = aUser.CreateDate;
            row.Password = aUser.Password;

            int debug = adpt.Update(row);
            return true;
        }
    }
    catch (Exception e)
    {
        MessageBox.Showe(e.ToString());
    }
    return false;
}
</code></pre>

<p>Here is the picture of my database structure:
<a href="https://i.stack.imgur.com/NtgiF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NtgiF.png" alt="enter image description here"></a></p>

<p>The <code>debug</code> always will be 0, which means nothing updated. How can I do it correctly? I am not going to allow any user to change <code>Email</code> (the Primary Key) now. However, if I want to user to be able to change everything including the Primary Key, how can I do it? My friend told me a solution: make a <code>List&lt;User&gt; allUser</code>, that contains every <code>user</code> information from the database. When a user makes a change, then update in the <code>allUser</code> first, and then clean every row in the database and re-add them with <code>allUser</code>. I tried, and it works but I do want to DO it so, because I do not want to remove every row and re-add it again, that is just wasting time and if two users using the database at the same time and both of them make changes, then the first one's change will be overwritten by the last one. So, I am wondering that is there any other better way to do it? </p>