Data exception error - why?

2 posts, 0 answers
  1. Karl
    Karl avatar
    226 posts
    Member since:
    Jun 2005

    Posted 20 Dec 2011 Link to this post

    Hi,
    I have a radgrid with the data loaded:

     

    OleDbDataReader reader = cmd.ExecuteReader();

    radGridView1.DataSource = reader;

    After editing a row, before the MasterTemplate_CellEndEdit fires (where I would manually update the changes in the table) I get the errormsg shown in the picture. Any clues?

    Karl


  2. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 23 Dec 2011 Link to this post

    Hello Karl,

    The problem is that directly binding the result of DbDataReader to RadGridView control will render ReadOnly IEnumerable data - the result of DbDataReader operation. To support editing of your data you must convert the reader IEnumerable result to list containing your custom business object. Here is a simple implementation of one:

    class MyObj
    {
        public string Area { get; set; }
        public string Category { get; set; }
        public string Right { get; set; }
        public decimal Amount { get; set; }
        public string Notes { get; set; }
    }
     
    BindingList<MyList> list = new BindingList<MyObj>();
     
    while (reader.Read())
    {
        string area = dbReader.GetValue(columnArea).ToString();
        string category = dbReader.GetValue(columnCategory).ToString();
        string right = dbReader.GetValue(columnRight).ToString();
        string amount = dbReader.GetValue(columnAmount).ToString();
        string notes = dbReader.GetValue(columnNotes).ToString();
        // fill the list with values
    }
     
    radGridView1.DataSource = list;

    I hope this helps. Let me know if you need further assistance.

    Kind regards,
    Julian Benkov
    the Telerik team

    Q3’11
    of RadControls for WinForms is available for download (see what's new). Get it today.
Back to Top