By Rafe Kemmis - 8/27/2007
I have a SF winform bound to one of my BO's that sits on top of a vfp oledb table. When I try to save a new row I get this:
BusinessLayerException
An error occurred while saving an the data to the server.
DataLayerSavingException
Field ORDERID does not accept null values.
OleDbException
Field ORDERID does not accept null values.
Source : MicroFour StrataFrame Business
Stack Trace:
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
at System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
at MicroFour.StrataFrame.Data.DbDataSourceItem.InternalExecuteNonQuery(DbCommand Command, Boolean IsTransactional, String TransactionKey)
at MicroFour.StrataFrame.Data.VfpDataSourceItem.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.SaveByForm(DataTable TableToSave, Boolean Transactional, String TransactionKey)
at MicroFour.StrataFrame.Business.BusinessLayer.SaveByForm(Boolean Transactional, String TransactionKey)
at MicroFour.StrataFrame.UI.Windows.Forms.BaseForm.Save(Boolean Transactional, String TransactionKey)
at MicroFour.StrataFrame.UI.Windows.Forms.BaseForm.Save()
at MicroFour.StrataFrame.UI.Windows.Forms.MaintenanceFormToolStrip.cmdSave_Click(Object sender, EventArgs e)
at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
at System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ToolStrip.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)
In VFP apps we usually keep track of the "next" key to use inside a special table... how do you suggest managing table keys of vfp tables in SF?
|
By StrataFrame Team - 8/28/2007
Yeah, we have a NextID table for our FoxPro, too. You'll need to set the PrimaryKeyIsAutoIncremented property on the business object to False so that tells the business object that you're going to supply the primary key. Then, create a stored procedure to retrieve and increment the value from the NextID table for the table you're trying to insert into. Lastly, call that stored procedure in the SetDefaultValues() of your business object which will retrieve the PK and set it on the record when you call BusinessObject.NewRow() or BusinessObject.Add().
|
By Rafe Kemmis - 8/28/2007
Thanks for the tip. Well I am getting close. I have the stored procedure created and functioning, called GetKey and it takes one parameter which is the table name, and returns the key as an integer.Now how to call it within SF? inside my_SetDefaultValues() : int newid = MicroFour.StrataFrame.Data.DataBasics.DataSources[""].ExecuteStoredProcedure("GetKey",DbCommandExecutionType.ExecuteScalar,***NOT SURE WHAT TO PUT HERE**); myBO.orderid = newid; Am I close?
|
By Rafe Kemmis - 8/28/2007
*closer*System.Data.OleDb. OleDbParameter param = new System.Data.OleDb.OleDbParameter();param.ParameterName = "tablename";param.Value = "orderheader";object x = MicroFour.StrataFrame.Data.DataBasics.DataSources[""].ExecuteStoredProcedure("GetKey", DbCommandExecutionType.ExecuteScalar, param); This may be a simple .net question... how do I "box" the object into an int? type-casting in front of the ExecuteStoredProcedure() call throws an exception... thanks in advance!
|
By Rafe Kemmis - 8/28/2007
Okay, this is working now:System.Data.OleDb. OleDbParameter param = new System.Data.OleDb.OleDbParameter("tablename", "orderheader"); decimal newid = (decimal)MicroFour.StrataFrame.Data.DataBasics.DataSources[""].ExecuteStoredProcedure("GetKey", DbCommandExecutionType.ExecuteScalar, param); orderBO1.orderid = newid;
|
By StrataFrame Team - 8/29/2007
Hehe, yep (typename) is the correct cast. Glad you got it working And technically when you go from an object to a value type, you're "unboxing" Wrapping a value in an object reference is "boxing."
|
|