Help with SQL Mobile and data sets

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RedSon
    Recognized Expert Expert
    • Jan 2007
    • 4980

    #1

    Help with SQL Mobile and data sets

    HELP!

    Code:
    private void dataGridView1_UserAddedRow(object sender, DataGridViewRowEventArgs e)
            {
                MessageBox.Show("dataGridView1_UserAddedRow");
                if (this.bookDataSet.HasChanges())
                {
                    DataSet changes = this.bookDataSet.GetChanges();
    
                    this.booksTableAdapter.Connection.Open();
                    this.booksTableAdapter.Update((BookApplication.bookDataSet)changes);
                    this.booksTableAdapter.Connection.Close();
                    this.bookDataSet.Merge(changes, true, MissingSchemaAction.Add);
    
                    DataRow[] errRows = this.bookDataSet.Tables["books"].GetErrors();
                    foreach (DataRow errRow in errRows)
                    {
                        errRow.RejectChanges();
                        errRow.RowError = null;
                    }
                    this.bookDataSet.AcceptChanges();
                }
            }
    The issue is when the user adds a row it throws an unhandled exception of type 'System.Data.Co nstraintExcepti on' occurred in System.Data.dll , but the only constraints that the DB has is that none of the columns can be null. But the user has not finished entering in the information into the datagridview yet so some of the colums will be null. I don't know what the heck is going on with this. I'm at my wits end....MSDN sucks.
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    Originally posted by RedSon
    The issue is when the user adds a row it throws an unhandled exception of type 'System.Data.Co nstraintExcepti on' occurred in System.Data.dll , but the only constraints that the DB has is that none of the columns can be null. But the user has not finished entering in the information into the datagridview yet so some of the colums will be null. I don't know what the heck is going on with this. I'm at my wits end....MSDN sucks.
    You have described the problem exactly. Either nulls are allowed or all columns changes are inserted at the same time. Consequently, all changes would need to be identified on one event (maybe tricky) or each change event updates all columns with new or current values (pretty inefficient).

    Would it be helpful to identfy only the changes to update and use these as parameters, rather than using one update statement in the dataadapter (updating everything?). I use stored procedures for these, but only sqlcommands available to you. HTH.

    Comment

    • RedSon
      Recognized Expert Expert
      • Jan 2007
      • 4980

      #3
      Originally posted by kenobewan
      You have described the problem exactly. Either nulls are allowed or all columns changes are inserted at the same time. Consequently, all changes would need to be identified on one event (maybe tricky) or each change event updates all columns with new or current values (pretty inefficient).

      Would it be helpful to identfy only the changes to update and use these as parameters, rather than using one update statement in the dataadapter (updating everything?). I use stored procedures for these, but only sqlcommands available to you. HTH.
      I guess I need to know what event is triggered when the user finishes editing a row. Then I can call getChanges then and I will have all values in each column and not need to worry about null values.

      Comment

      • RedSon
        Recognized Expert Expert
        • Jan 2007
        • 4980

        #4
        Originally posted by RedSon
        I guess I need to know what event is triggered when the user finishes editing a row. Then I can call getChanges then and I will have all values in each column and not need to worry about null values.
        I think I got it figured out. The problem was with the merge call. The data set that the user updates already has the changes so mergeing them just merges double the data, and when you have values that must be unique it throws errors.

        Comment

        Working...