Here I will post problems I and my colleagues met and solutions we found.

Wednesday, March 16, 2005

ReadOnly Exception Error when Inserting with an Expression Column

This is well known problem. That means this is an issue for many people and we could not pass it.

The problem is that if DataTable has expression columns, and Insert (or Update) SQLCommand returns some values, exception will be raised that ReadOnly property cannot be changed.

There is workaround. I may try manually refresh data and updat field values. Something like this:


SqlDataReader r = employeeRecordCommand.ExecuteReader(CommandBehavior.SingleRow);
if (r.HasRows)
{
r.Read();
for (int i = 0; i < r.FieldCount; i++)
{
string s = r.GetName(i);
if (string.Compare(s, "contact_id", true) != 0)
{
if (dataRow.Table.Columns.Contains(s))
dataRow[s] = r[i];
}
}
}
r.Close();


Here is the link to description of the problem:
http://www.error-bank.com/microsoft.public.dotnet.framework.windowsforms.databinding/_35_HCSYiV0DHA.2328@TK2MSFTNGP10.phx.gbl_Thread.aspx

No comments: