Information générale
Catégorie:
The Mere Mortals .NET Framework
Titre:
Identity columns and read only error
When I run the following code against a table with a primary key that is an identity column in SQL Server, I get the error "Column 'pri_key' is Read Only"
DataSet DS = oMyBizObj.GetByID(1);
// Add a DataRow to a table.
DataRow myRow = DS.Tables["MyTable"].NewRow();
myRow["MyColumn1"] = 1;
myRow["MyColumn2"] = "ABC";
// Add the row.
DS.Tables["MyTable"].Rows.Add( myRow );
DS.AcceptChanges();
oMyBizObj.UpdateFromDataSet(DS);
I'm not writing any value to the pri_key column assuming SQL Server will fill it in for me. I've seen help topics and posts concerning retrieving the new value into the data set, but haven't come across this error.
Thanks in advance,
Mike
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement