PC Review


Reply
Thread Tools Rate Thread

addnew row problem

 
 
Roman Chumakov
Guest
Posts: n/a
 
      7th Oct 2003
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


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with .addnew LaurieTuff via AccessMonster.com Microsoft Access Queries 9 23rd Jan 2008 05:40 PM
.addnew problem =?Utf-8?B?SmltaA==?= Microsoft Access Form Coding 3 22nd Aug 2007 10:30 PM
AddNew Method Problem Retort Microsoft Access Form Coding 2 14th Nov 2005 10:16 PM
CurrencyManager.AddNew problem James Goodman Microsoft Dot NET Compact Framework 0 6th Jun 2005 04:04 PM
Re: Datagrid AddNew problem better@medianis.net Microsoft Dot NET Compact Framework 0 28th Dec 2004 11:35 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:02 AM.