Unexpected problem inserting


Author
Message
Daniel Essin
Daniel Essin
StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 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.
Reply
Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
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