When I save I get an error that says


Author
Message
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
A better place would be using the SetDefaultValues event. I typically handle it in the BO and then you don't have to worry about it.
Marcia G Akins
Marcia G Akins
Advanced StrataFrame User (510 reputation)Advanced StrataFrame User (510 reputation)Advanced StrataFrame User (510 reputation)Advanced StrataFrame User (510 reputation)Advanced StrataFrame User (510 reputation)Advanced StrataFrame User (510 reputation)Advanced StrataFrame User (510 reputation)Advanced StrataFrame User (510 reputation)Advanced StrataFrame User (510 reputation)
Group: StrataFrame Users
Posts: 322, Visits: 529
I tried leaving it set to false - same problem. So, I did this in the BO's BeforeSave method and that took care of the problem:

// when all else fails, try a bigger hammer

// kept getting a "column does not accept null values" error

// on save

if (chkis_primary.Checked == false)

    boContact.is_primary = false;

 


Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
And as I reread the docs, they appear to be backwards. I.e. based on docs true would initialize, but in source, its obviously false that causes the initialization...



If Not _AllowNullValuesOnNewRow Then

  '-- initialization code

End If

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
It appears that if you want the BO to initialize your columns with default data based on the data type, you need to set the AllowNullValuesOnNewRow property to false. If it is true, it allows NULLs in the current data table. If false, then it does the initialization. (checked source to figure out what was up).
Marcia G Akins
Marcia G Akins
Advanced StrataFrame User (510 reputation)Advanced StrataFrame User (510 reputation)Advanced StrataFrame User (510 reputation)Advanced StrataFrame User (510 reputation)Advanced StrataFrame User (510 reputation)Advanced StrataFrame User (510 reputation)Advanced StrataFrame User (510 reputation)Advanced StrataFrame User (510 reputation)Advanced StrataFrame User (510 reputation)
Group: StrataFrame Users
Posts: 322, Visits: 529
And I really do not understand why. I set the BO's AllowNullValuesOnNewRow property to true because From the documentation (even though it sounds a little backwards Tongue):

When True, the NewRow() function will automatically initialze the row to prevent any DBNull values from occurring

In the BO mapper, I also customized the field to return alternate on null - is_primary is a boolean field, so I set the alternate to false.

So I am more than a little mystified that I am getting this error - can someone please help me find a solution?

DataLayerSavingException
  Cannot insert the value NULL into column 'is_primary', table 'TGIF.dbo.Contact'; column does not allow nulls. INSERT fails.
The statement has been terminated.
SqlException
  Cannot insert the value NULL into column 'is_primary', table 'TGIF.dbo.Contact'; column does not allow nulls. INSERT fails.
The statement has been terminated.

Source     : MicroFour StrataFrame Business

Stack Trace:
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
   at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
   at System.Data.SqlClient.SqlDataReader.get_MetaData()
   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
   at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
   at MicroFour.StrataFrame.Data.DbDataSourceItem.InternalExecuteReader(DbCommand Command, Boolean IsTransactional, String TransactionKey)
   at MicroFour.StrataFrame.Data.SqlDataSourceItem.UpdateRow(QueryInformation QueryInfo, DataRow RowToUpdate, ConcurrencyExceptionHandler ConcurrencyHandler, AddRowErrorHandler RowErrorHandler, Boolean RecreateCommand)
   at MicroFour.StrataFrame.Data.DbDataSourceItem.UpdateRow(QueryInformation QueryInfo, DataRow RowToUpdate, ConcurrencyExceptionHandler ConcurrencyHandler, AddRowErrorHandler RowErrorHandler)
   at MicroFour.StrataFrame.Data.DataLayer.UpdateDataTableThread(Object ThreadParams)
   at MicroFour.StrataFrame.Data.DataLayer.UpdateDataTable(DataTable TableToUpdate, Boolean Transactional, String TransactionKey)
   at MicroFour.StrataFrame.Data.DataLayer.Save(DataTable TableToSave, Boolean Transactional, String TransactionKey)
   at MicroFour.StrataFrame.Business.BusinessLayer.Save(Boolean Transactional, String TransactionKey)
   at MicroFour.StrataFrame.Business.BusinessLayer.Save()
   at TGIF.Forms.Contact.cmdOK_Click(Object sender, EventArgs e) in F:\TGIF\Forms\Contact.cs:line 109
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativewindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativewindow.WndProc(Message& m)
   at System.Windows.Forms.Nativewindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

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