Maintennace Forms and PK queries


Author
Message
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
No problem, Ian.  Glad you got it figured out.
Ian Hammond
Ian Hammond
StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)
Group: Forum Members
Posts: 57, Visits: 277
Trent,

Thanks for those pointers. I have now sorted my Pk issue. Not only am I trying to get to grips with StrataFrame but I am also learning what I can do with SQL Server Express and I had overlooked a column property when defining a primary key.

Regards

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
This appears that you do not have a seed on your primary key.  The only way that you would get this is one of the following ways:

  • You are expecting the BO to support Auto-Incrementing keys and do no have your PK setup with an auto-incrementing seed on your table.
  • You have a PK field defined on your table and are supposed to set this yourself as it is not auto-incrementing and then do not set this value.
  • You are using CRUD sprocs and have created these manually and are not updating the PK field.

The manifestation of your issue will be one of these elements.  There may be some other factors involved, but the root is going to most likely be one of these things (or a combination of them).

Ian Hammond
Ian Hammond
StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)
Group: Forum Members
Posts: 57, Visits: 277
When I execute my Save command from the Maintenance form I get the following message dumped:

BusinessLayerException
  An error occurred while saving an the data to the server.
DataLayerSavingException
  Cannot insert the value NULL into column 'config_pk', table 'ConfigHLS.dbo.Config'; column does not allow nulls. INSERT fails.
The statement has been terminated.
SqlException
  Cannot insert the value NULL into column 'config_pk', table 'ConfigHLS.dbo.Config'; 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()
   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.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)

I have also switched debug on and the last sql command is:

Command #: 4
Timestamp: 2009-04-29 13:24:52.312
General Command Settings
Command Type: Text
Object Type: System.Data.SqlClient.SqlCommand
Connection String: Data Source=IANASUS\SQLEXPRESS;Initial Catalog=ConfigHLS;Integrated Security=True;Persist Security Info=False;Asynchronous Processing=True
Transaction: False
Command Settings
CommandText: INSERT INTO [dbo].[Config] ([tableId], [fieldName], [displayName], [pageNo], [pagePosn], [fieldType], [entries], [multiChoice], [enquire], [checkSpell], [inReview], [length], [lines], [contents]) VALUES (@tableId, @fieldName, @displayName, @pageNo, @pagePosn, @fieldType, @entries, @multiChoice, @enquire, @checkSpell, @inReview, @length, @lines, @contents); SELECT [config_pk] FROM [dbo].[Config] WHERE config_pk = SCOPE_IDENTITY();
Command Parameters
@tableId: '1' [DbType: Int32 | Size: 0 | Direction: Input | SourceColumn: tableId | SourceVersion: Current]
@fieldName: ' Genus' [DbType: String | Size: 52 | Direction: Input | SourceColumn: fieldName | SourceVersion: Current]
@displayName: 'Genus' [DbType: String | Size: 52 | Direction: Input | SourceColumn: displayName | SourceVersion: Current]
@pageNo: '0' [DbType: Int32 | Size: 0 | Direction: Input | SourceColumn: pageNo | SourceVersion: Current]
@pagePosn: '0' [DbType: Int32 | Size: 0 | Direction: Input | SourceColumn: pagePosn | SourceVersion: Current]
@fieldType: '1' [DbType: Int32 | Size: 0 | Direction: Input | SourceColumn: fieldType | SourceVersion: Current]
@entries: 'False' [DbType: Boolean | Size: 0 | Direction: Input | SourceColumn: entries | SourceVersion: Current]
@multiChoice: 'False' [DbType: Boolean | Size: 0 | Direction: Input | SourceColumn: multiChoice | SourceVersion: Current]
@enquire: 'False' [DbType: Boolean | Size: 0 | Direction: Input | SourceColumn: enquire | SourceVersion: Current]
@checkSpell: 'False' [DbType: Boolean | Size: 0 | Direction: Input | SourceColumn: checkSpell | SourceVersion: Current]
@inReview: 'False' [DbType: Boolean | Size: 0 | Direction: Input | SourceColumn: inReview | SourceVersion: Current]
@length: '10' [DbType: Int32 | Size: 0 | Direction: Input | SourceColumn: length | SourceVersion: Current]
@lines: '1' [DbType: Int32 | Size: 0 | Direction: Input | SourceColumn: lines | SourceVersion: Current]
@contents: ' ' [DbType: String | Size: -1 | Direction: Input | SourceColumn: contents | SourceVersion: Current]

 I hope this is of some use

Ian Hammond
Ian Hammond
StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)
Group: Forum Members
Posts: 57, Visits: 277
Hi Paul,

Sorry about the delay in responding. I am trying to insert a new record. I have declared the pk to be an integer. In the Business object I have :

PrimaryKeyIsAutoIncremented= true and PrimaryKeyIsUpdatable=false.

Many thanks

Ian Hammond
Ian Hammond
StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)
Group: Forum Members
Posts: 57, Visits: 277
Hi Greg,

Thanks for the reply. Sorry about the delay in responding. I will try and lay-out what I'm trying to achieve. I want to have 2 fields in a configuration database labeled FieldName and DisplayName say. These fields are bound to textBox1 and textBox2 respectively. I am trying to initialise textBox2 with the contents of textBox1 as the user is entering into textBox1. The user can change the displayname independently by entering into textBox2.

Many thanks

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
All good questions from the guys, Ian.  Could you elaborate on #1 what you are trying to accomplish.  Also, Paul's questions on #2 are needed to help as well.  Thanks.
Paul Chase
Paul Chase
Advanced StrataFrame User (580 reputation)Advanced StrataFrame User (580 reputation)Advanced StrataFrame User (580 reputation)Advanced StrataFrame User (580 reputation)Advanced StrataFrame User (580 reputation)Advanced StrataFrame User (580 reputation)Advanced StrataFrame User (580 reputation)Advanced StrataFrame User (580 reputation)Advanced StrataFrame User (580 reputation)
Group: Forum Members
Posts: 414, Visits: 2.8K
Hi Ian,

For you # 1 question try handling the property changing event on the business object. To enable the event look under advanced options in the business object mapper. you should be able to handle it and do something like to code below to accomplish what you want

Private Sub BizCustomers1_FieldPropertyChanging(ByVal sender As Object, ByVal e As BizCustomers.BizCustomersFieldChangingEventArgs) Handles BizCustomers1.FieldPropertyChanging

If e.FieldChanging = BizCustomers.BizCustomersFieldNames.cust_Name Then

'check to see if adding

If Me.BizCustomers1.EditingState = BusinessEditingState.Adding Then

'set shrtname field to the first 7 characters of the customer name while adding

Me.BizCustomers1.cust_ShrtName = Me.BizCustomers1.cust_Name.PadRight(7, " ").Substring(0, 7)

End If

End If

End Sub

For # 2 are you only getting the error when you update a record?

Are you using an integer PK and having SQL handle the increment or are you passing in your own PK?

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Ian,



I'm not following what your are trying to do in #1. In number two, you likely need to handle the SetDefaultValues for the BO and set some defaults. Value types (structures) will have a default set automatically, but reference types are null (Nothing) by default. So, if one of those fields is marked Not Null, you'll get this kind of error.
Ian Hammond
Ian Hammond
StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)
Group: Forum Members
Posts: 57, Visits: 277
Hi,

I have the following 2 queries:

1) I have a maintenance form with 2 bound textboxes, 1 textbox for a db field name (textBox1) and the other for a friendly display name (textBox2). During New i would like the friendly name to be the mirror of the field name whilst the user is inputting the data. I have set. In the Change event on textBox1 I set

     textBox2.Text = textBox.Text

When I run the app and attempt to create a new record, I enter a character into textBox1 the change event is invoked and the data is copied to textBox2 but then the character is obliterated. Any subsequent keypress results in a blank textBox1 and textBox2. I have noticed that there seems to be multiple calls to the change event when a single key is pressed.  Does anyone have an explanation for this?

2) When I update a new record I get the error "Cannot insert the value NULL into config_pk etc. I have the properties on the PrimaryKeyIsAtoIncremented= True and PrimaryKeyIsUpdateable= false. Is there another property that I should look out for?

many thanks

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