StrataFrame Forum
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      



Unexpected problem insertingExpand / Collapse
Author
Message
Posted 03/12/2006 10:38:24 PM
StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: Forum Members
Last Login: 05/25/2007 3:34:57 PM
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]
) 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.
Post #620
Posted 03/12/2006 11:01:54 PM
StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: Forum Members
Last Login: 05/25/2007 3:34:57 PM
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)"
Post #621
Posted 03/12/2006 11:09:11 PM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: Today @ 3:06:58 PM
Posts: 4,599, Visits: 4,576
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.

Post #622
Posted 03/13/2006 1:17:09 PM
StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: Forum Members
Last Login: 05/25/2007 3:34:57 PM
Posts: 235, Visits: 309
Both fields in the BO contained valid strings at the time the Save() error occurred.
Post #630
Posted 03/13/2006 2:54:08 PM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: Today @ 3:06:58 PM
Posts: 4,599, Visits: 4,576
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.

Post #633
Posted 03/14/2006 4:02:22 PM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: Today @ 3:06:58 PM
Posts: 4,599, Visits: 4,576
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.

Post #639
« Prev Topic | Next Topic »


Reading This TopicExpand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Ben Chase, Trent L. Taylor, Steve L. Taylor

PermissionsExpand / Collapse

All times are GMT -6:00, Time now is 4:23pm

Powered by InstantForum.NET v4.1.4 © 2008
Execution: 0.156. 12 queries. Compression Enabled.
Site Map - Home - My Account - Forum - About Us - Contact Us - Try It - Buy It

Microsoft, Visual Studio, and the Visual Studio logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries.