I have problems adding new row to my table.
on asp.net web form I get a table from db, then I save it to session.
During postback I get the table from session and try to add new row to it.
But I can't! Please, help!
My code is here:
---------------------
//If not postback I do:
DataTable table = getTableFromDB();
SaveTableFromSession();
....
//If this is postback I try to add a row to my table:
table = GetTableFromSession();
DataRow addedRow;
addedRow = table.NewRow();
addedRow["id"]=-1; // This line is ignored, because of identity
addedRow.EndEdit();
//Next line throws an error exception (see bottom of this posting)
table.Rows.Add(addedRow);
---
DataTable getTableFromDB(){
SqlConnection conn = dbUtil.getConnection();
string sql = "select * from Items";
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
DataSet ds = new DataSet();
da.Fill(ds);
DataTable t = ds.Tables[0];
return t;
}
---------------------------
In sqlserver:
The table "Items" has primary key "id". Plus column "id" is identity.
The line:
da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
does'nt help me

(
--------------------------------
The ERROR IS:
Column 'id' does not allow nulls.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.Data.NoNullAllowedException: Column 'id' does not
allow nulls.
Please, help me to add a new row to my table.
Sincerelly yours,
Ruslan