new_user_xyz
asked on
ADO.NET: Problems when adding a new datarow to a datatable
Hello,
problem is the following:
I created a dataset and read a datatable from the database. If I want to add a new row to the
datatable I receive an error:
"Column ' name_of_pk ' does not permit zero value
Stack Trace:
at System.Data.DataTable.Inse rtRow(Data Row row, Int32 proposedID, Int32 pos)
at System.Data.DataTable.AddR ow(DataRow row, Int32 proposedID)
at System.Data.DataRowCollect ion.Add(Da taRow row)
My code is the following:
because I use dataview's at the UI, I have to set the primary key for the datatable in order to find the selected columns from the dataview in the datatable.
.....
myDataSet.Tables["tablenam e"].Primar yKey =
new DataColumn[] {myDataSet.Tables["tablena me"].Colum ns["name_o f_pk"]};
......
DataRow theNewRow = myDataSet.Tables["tablenam e"].NewRow ();
myDataSet.Tables["tablenam e"].Rows.A dd( theNewRow ); <- the error occures here
......
The primary key in the database is set to autoincrement and I don't want to handle the primarykey in my application.
Is there a way to add the new Row to the DataTable without a value for the primary key?
Does anybody know a solution to that problem?
thanx in advance ;-)
problem is the following:
I created a dataset and read a datatable from the database. If I want to add a new row to the
datatable I receive an error:
"Column ' name_of_pk ' does not permit zero value
Stack Trace:
at System.Data.DataTable.Inse
at System.Data.DataTable.AddR
at System.Data.DataRowCollect
My code is the following:
because I use dataview's at the UI, I have to set the primary key for the datatable in order to find the selected columns from the dataview in the datatable.
.....
myDataSet.Tables["tablenam
new DataColumn[] {myDataSet.Tables["tablena
......
DataRow theNewRow = myDataSet.Tables["tablenam
myDataSet.Tables["tablenam
......
The primary key in the database is set to autoincrement and I don't want to handle the primarykey in my application.
Is there a way to add the new Row to the DataTable without a value for the primary key?
Does anybody know a solution to that problem?
thanx in advance ;-)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Bob