none
Doesn't parse updated row from LinqToSQLDataClass to Database LINQ C# WPF RRS feed

  • Question

  • I'm building an Edit/Update system in my program using Linq in C# WPF. My problem is that my code does submit to the LinqToSQLDatacontex but doesn't parse it through to the actual Database.

    The result of that is that the datarow is updated in Runtime but in fact isn't updated in the actual Database.

    use for Updating my rows.

    private void dgUsers_MouseUp(object sender, MouseButtonEventArgs e)
        {
            try
            {
                item = dgUsers.SelectedItem;
                string name = (dgUsers.SelectedCells[0].Column.GetCellContent(item) as TextBlock).Text;
    
                var query =
                    from t in db.tbl_Users
                    where t.Name == name
                    select t;
    
                foreach (var q in query)
                {
                    tbMoreName.Text = q.Name;
                    tbMoreRights.Text = q.Rights;
                    tbMoreTag.Text = q.Operatortag;
                    checkMoreActive.IsChecked = q.Active;
                    tbMoreCardCode.Text = q.CardCode;
                }
    
                var table =
                    from q in db.tbl_UserProfiles
                    where q.Userprofile == tbMoreRights.Text
                    select q;
            }
            catch (Exception exc)
            {
                MessageBox.Show("NOPE");
            }
        }
    
     private void btnSaveUser_Click(object sender, RoutedEventArgs e)
            {
                switch (saveType)
                {
                    
    
                    case "Edit":
                        #region save Edit User
    
                        var edit =
                            (from t in db.tbl_Users
                             where t.Name == name
                             select t).First();
    
                        MessageBox.Show(edit.Id.ToString() + " " + edit.Name.ToString() + " " + edit.Operatortag.ToString() + " " + edit.Rights.ToString() + " " + edit.Active.ToString());
    
                        edit.Id = edit.Id;
                        edit.Name = tbName.Text;
                        edit.Operatortag = tbOperatortag.Text;
                        edit.Rights = cbRights.Text;
                        edit.Active = checkActive.IsChecked.Value;
                        edit.CardCode = tbCardcode.Text;
    
                        MessageBox.Show(edit.Id.ToString() + " " + edit.Name.ToString() + " " + edit.Operatortag.ToString() + " " + edit.Rights.ToString() + " " + edit.Active.ToString() + " " + edit.CardCode.ToString());
    
                        db.SubmitChanges();
    
                        #endregion
                        saveType = "";
                        break;
                }
                var refresh =
                            (from q in db.tbl_Users
                             select new { Name = q.Name, Rights = q.Rights, Operatortag = q.Operatortag, Active = q.Active, Cardcode = q.CardCode }).ToList();
    
                dgUsers.ItemsSource = null;
                dgUsers.ItemsSource = refresh;
                MessageBox.Show(refresh[0].ToString() + " " + refresh[1].ToString() + " " + refresh[2].ToString() + " " + refresh[3].ToString() + " " + refresh[4].ToString());
            }



    I hope that one of you guys can help me. Thanks in advance!!!


    Thursday, March 9, 2017 10:36 AM

All replies

  • Hi programming wolf,

    thanks for posting here.

    Do you encounter any exception?

    Based on your description and related code, I create a simple demo, it works well, please check if you refresh your data table.

    In addition, please check if you connect the right table.

    Best regards,

    Cole Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, March 10, 2017 5:40 AM
    Moderator
  • Hey Moderator,

    I found my problem, My Database Property was set on Copy Always and when I changed it to Copy If Newer, it worked

    Thanks for your time and efford

    Your's truely,

    Tuesday, March 14, 2017 8:11 AM
  • Hi programming,

    I am glad to know that you resolve the issue and share the solution, please mark it as answer, it will be beneficial to other communities who have the similar issue.

    Best regards,

    Cole Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, March 15, 2017 6:42 AM
    Moderator