DataGridView DataSource Add/Remove Row

2 posts, 0 answers
  1. David
    David  avatar
    66 posts
    Member since:
    Aug 2010

    Posted 29 Nov 2011 Link to this post

    Hi,

    I have just started looking into using the Open Access ORM and currently have the following set-up on my form.


    Context dbcontext  = new Context();
      
    Void LoadData()
    {
      
    var T001 = new ObservableCollection<T001_Table>(dbcontext.T001_Table.Where(p => p.Group_Code == (int)comboBox1.SelectedValue));
      
    T001.CollectionChanged += new NotifyCollectionChangedEventHandler(T001_CollectionChanged);
    this.dataGridView1.DataSource = new BindingSource() { DataSource = T001 };
      
    }
      
    void T001_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
    {
        if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
            dbcontext.Add(e.NewItems);
      
      
        if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove)
            dbcontext.Delete(e.OldItems);
    }
      
    private void button1_Click(object sender, EventArgs e)
    {
        if (MessageBox.Show(this, "Save Changes?", "Save Changes?", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
       {
        try
            {
                  dbcontext.SaveChanges();
                  MessageBox.Show("Data Saved");
            }
            catch (Exception Ex)
            {
               MessageBox.Show(Ex.Message);
             }
    }
      
    }

    This works ok if i'm just updating a value in the table but if i add a new row or delete a row i get the following Excpetion:

    Insert of '1361221285-' failed: Telerik.OpenAccess.RT.sql.SQLException: Invalid column name 'ColumnA2'.
    Invalid column name 'ColumnB2'.
    Invalid column name 'ColumnC2'.
    Invalid column name 'ColumnD2'.
    Invalid column name 'ColumnE2'.
    Invalid column name 'ColumnF2'.
    Statement(s) could not be prepared.
       at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.execute()
       at OpenAccessRuntime.Relational.conn.PooledPreparedStatement.execute()
       at OpenAccessRuntime.Relational.RelationalStorageManager.generateInserts(NewObjectOID oid, Int32 index, ClassMetaData cmd, PersistGraph graph, Int32[] fieldNos, CharBuf s, Object[] oidData, IntArray toUpdateIndexes)
    INSERT INTO [T001_Table] ([ColumnA], [ColumnB], [ColumnC], [ColumnD], [ColumnE], [ColumnF], [ColumnG], [ColumnH], [ColumnI], [ColumnJ], [ColumnK], [ColumnL], [ColumnN], [ColumnO], [ColumnP], [ColumnQ], [ColumnR], [ColumnS], [ColumnT], [UColumn], [ColumnA2], [ColumnB2], [ColumnC2], [ColumnD2], [ColumnE2], [ColumnF2], [ColumnU], [ColumnV], [ColumnW], [ColumnX], [ColumnY], [ColumnZ]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
    select scope_identity()
    (set event logging to all to see parameter values) Telerik.OpenAccess.RT.sql.SQLException: Invalid column name 'ColumnA2'.
    Invalid column name 'ColumnB2'.
    Invalid column name 'ColumnC2'.
    Invalid column name 'ColumnD2'.
    Invalid column name 'ColumnE2'.
    Invalid column name 'ColumnF2'.
    Statement(s) could not be prepared.
       at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.execute()
       at OpenAccessRuntime.Relational.conn.PooledPreparedStatement.execute()
       at OpenAccessRuntime.Relational.RelationalStorageManager.generateInserts(NewObjectOID oid, Int32 index, ClassMetaData cmd, PersistGraph graph, Int32[] fieldNos, CharBuf s, Object[] oidData, IntArray toUpdateIndexes)


    I seems to have duplicated some of my Columns. Could this be something to do with my Foreign Keys?


    Thanks
  2. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 02 Dec 2011 Link to this post

    Hi David ,

    There was an issue in the Q3 release with the attributes mapping which could result in lost mapping for associations. If you are using attributes mapping, please download the latest internal build, which was released this week, it should fix the problem.

    If this is not the case, you could have a look at the Mapping Details Editor and check whether the property / column mappings are correct for the class that causes the exception.
    If this does not help, please let us know, so we can investigate the problem further.

    Greetings,
    Alexander
    the Telerik team
    Want to use Telerik OpenAccess with SQL Azure? Download the trial version today. 
  3. DevCraft banner
Back to Top