This is a migrated thread and some comments may be shown as answers.

Data exception error - why?

1 Answer 208 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Karl
Top achievements
Rank 1
Karl asked on 20 Dec 2011, 07:01 PM
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


1 Answer, 1 is accepted

Sort by
1
Julian Benkov
Telerik team
answered on 23 Dec 2011, 10:23 AM
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.
Tags
GridView
Asked by
Karl
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
Share this question
or