Unexpected problem inserting


Author
Message
Daniel Essin
Daniel Essin
StrataFrame User (275 reputation)StrataFrame User (275 reputation)StrataFrame User (275 reputation)StrataFrame User (275 reputation)StrataFrame User (275 reputation)StrataFrame User (275 reputation)StrataFrame User (275 reputation)StrataFrame User (275 reputation)StrataFrame User (275 reputation)
Group: Forum Members
Posts: 235, Visits: 309
This is the code:

_EntityProgram.Add();

_EntityProgram.MRN = _Entity.MRN;

_EntityProgram.EnrolledProgram = comboPrograms.Text;

_EntityProgram.Save();



_EntityProgram is an instance of a BO



This is the DDL for the table behind the BO:

CREATE TABLE [dbo].[EntityProgram] (

   [MRN] [varchar] (36) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,

   [EnrolledProgram] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL

) ON [PRIMARY]

GO



ALTER TABLE [dbo].[EntityProgram] WITH NOCHECK ADD

   CONSTRAINT [PK_EntityProgram] PRIMARY KEY CLUSTERED

   (

      [MRN],

      [EnrolledProgram]

   Wink ON [PRIMARY]

GO



It's complaining about converting varchar to numeric but both fields are varchar and both are part of the PK.



This is the Error:

Cannot insert the value NULL into column 'EnrolledProgram', table 'CRM.dbo.EntityProgram'; column does not allow nulls. INSERT fails.

Error converting data type varchar to numeric.
Daniel Essin
Daniel Essin
StrataFrame User (275 reputation)StrataFrame User (275 reputation)StrataFrame User (275 reputation)StrataFrame User (275 reputation)StrataFrame User (275 reputation)StrataFrame User (275 reputation)StrataFrame User (275 reputation)StrataFrame User (275 reputation)StrataFrame User (275 reputation)
Group: Forum Members
Posts: 235, Visits: 309
You probably need the stack trace:

" at MicroFour.StrataFrame.Business.BusinessLayer.SaveBase(Boolean Transactional, String TransactionKey)\r at MicroFour.StrataFrame.Business.BusinessLayer.Save()\r at DSM.FormSelectEntity.buttonEnroll_Click(Object sender, EventArgs e) in E:\\_work.NET\\DSM\\DSM\\FormSelectEntity.cs:line 139\r at System.Windows.Forms.Control.OnClick(EventArgs e)\r at System.Windows.Forms.Button.OnClick(EventArgs e)\r at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)\r at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)\r at System.Windows.Forms.Control.WndProc(Message& m)\r at System.Windows.Forms.ButtonBase.WndProc(Message& m)\r at System.Windows.Forms.Button.WndProc(Message& m)\r at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)\r at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)\r at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)"
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
By default a business object does not allow NULL values.  To add NULL value support you need to do two things.

1. Set the AlloNullValuesOnNewRow to True on the BO itself.
2. Next, in the BO Mapper, you can specify NULL support.  There are two options, Generic Nullable and Return Alternate Value on NULL.  This does not affect the data on the server, but adds support to the strong-typed properties so the controls can interact without failing.  The most common option is Return Alternate on NULL.  When using this method, simply put the desired return value on in the text spacea below.  If you want to return an empty string, simply put the following value in the provided field: ""

This should resolve this error.

Daniel Essin
Daniel Essin
StrataFrame User (275 reputation)StrataFrame User (275 reputation)StrataFrame User (275 reputation)StrataFrame User (275 reputation)StrataFrame User (275 reputation)StrataFrame User (275 reputation)StrataFrame User (275 reputation)StrataFrame User (275 reputation)StrataFrame User (275 reputation)
Group: Forum Members
Posts: 235, Visits: 309
Both fields in the BO contained valid strings at the time the Save() error occurred.
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
I don't have enough info to give you an answer.  I need to you do two things.  First see if there is an inner exception.  Also, what could really help is a screen shot of the contents of the CurrentDataTable.  To get this do the following:

1. Put a breakpoint on the Save() method.
2. In the watch window put YourBOInstance.CurrentDataTable
3. Click the magnifying glass to the right of the value.  This will bring up a browse window
and show the contents. 

If you can give me a screen shot it would help.  You will probably have to email the image since it will be shrunk in the forum update.

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Daniel,

The problem was actually very simple.  To resolve your error, set the PrimaryKeyIsAutoIncremented property on the EntityProgram business object to False.  Since your database does not automatically increment the PK the value is NULL when it is attempting return the new PK value which is causing your problem.

In your case, set the PrimaryKeyIsAutoIncremented to False in the designer of the business object since you will never want this particular BO to pull an auto-incremented PK back from the server on a new row.  Keep this in mind for your other BOs as well.

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search