Primary Key, Identity Column - Problem adding row to strongly typed data table - "Column 'ShipmentID

S

stephanieschipper

All,

I am using a strongly typed data table generated from a SQL Server data
table that uses a primary key field ShipmentID that is also an identity
column.

The problem seems to be that the auto-generated code below:

public void AddShippingRequestRow(ShippingRequestRow row) {
Line 479: this.Rows.Add(row);

tries to add the row to the data table object which then throws an
error becuase the column is not nullable.

How do I get around this? Is there somewhere in the schema definition
file, or table adapter that I can specify that the primary key column
can be null when adding a row? The column must remain NULL in SQL
Server becuase it is a primary key.

I have created a business logic layer on top of the Data Table and
Table Adapter. I am then using an object data source and a FormView
control to access the data. The Insert command is working fine and
getting all the way to the object data source, but errors on adding the
row.

Thanks,

Steph.

The stack trace is below:


Source Error:


Line 477: [System.Diagnostics.DebuggerNonUserCodeAttribute()]
Line 478: public void AddShippingRequestRow(ShippingRequestRow
row) {
Line 479: this.Rows.Add(row);
Line 480: }
Line 481:


Source File: c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary
ASP.NET Files\shippingrequest\2bbe1126\20355fbe\App_Code.ufjeieot.1.cs
Line: 479

Stack Trace:


[NoNullAllowedException: Column 'ShipmentID' does not allow nulls.]
System.Data.DataColumn.CheckNullable(DataRow row) +1967055
System.Data.DataTable.RaiseRowChanging(DataRowChangeEventArgs args,
DataRow eRow, DataRowAction eAction, Boolean fireEvent) +133
System.Data.DataTable.SetNewRecordWorker(DataRow row, Int32
proposedRecord, DataRowAction action, Boolean isInMerge, Int32
position, Boolean fireEvent, Exception& deferredException) +265
System.Data.DataTable.InsertRow(DataRow row, Int32 proposedID, Int32
pos, Boolean fireEvent) +254
System.Data.DataRowCollection.Add(DataRow row) +20
ShippingRequestDataTable.AddShippingRequestRow(ShippingRequestRow
row) in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET
Files\shippingrequest\2bbe1126\20355fbe\App_Code.ufjeieot.1.cs:479
ShippingRequest.AddShippingRequest(String shipToType, String
shipToName, String shipToAddress1, String shipToAddress2, String
shipToAddress3, String shipToCity, String shipToState, String
shipToZip, String shipToPhone, String shipVia, String requestedBy,
Nullable`1 requestorPhoneExt, Nullable`1 requestorDeptNumber,
Nullable`1 numberOfPackages, String weight, String courierUsed,
Nullable`1 freightCharges, String wayBillNumber, String notes, String
createdBy) in
c:\Inetpub\wwwroot\ShippingRequest\App_Code\BLL\ShippingRequest.cs:66

[TargetInvocationException: Exception has been thrown by the target of
an invocation.]
System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[]
arguments, SignatureStruct& sig, MethodAttributes methodAttributes,
RuntimeTypeHandle typeOwner) +0
System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[]
arguments, Signature sig, MethodAttributes methodAttributes,
RuntimeTypeHandle typeOwner) +72
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags
invokeAttr, Binder binder, Object[] parameters, CultureInfo culture,
Boolean skipVisibilityChecks) +358
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags
invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
+29

System.Web.UI.WebControls.ObjectDataSourceView.InvokeMethod(ObjectDataSourceMethod
method, Boolean disposeInstance, Object& instance) +482

System.Web.UI.WebControls.ObjectDataSourceView.InvokeMethod(ObjectDataSourceMethod
method) +38

System.Web.UI.WebControls.ObjectDataSourceView.ExecuteInsert(IDictionary
values) +867
System.Web.UI.DataSourceView.Insert(IDictionary values,
DataSourceViewOperationCallback callback) +72
System.Web.UI.WebControls.FormView.HandleInsert(String commandArg,
Boolean causesValidation) +388
System.Web.UI.WebControls.FormView.HandleEvent(EventArgs e, Boolean
causesValidation, String validationGroup) +623
System.Web.UI.WebControls.FormView.OnBubbleEvent(Object source,
EventArgs e) +95
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs
args) +35
System.Web.UI.WebControls.FormViewRow.OnBubbleEvent(Object source,
EventArgs e) +109
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs
args) +35
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e)
+115
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String
eventArgument) +163

System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
+174
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+5102
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top