Can not Insert Null Value When I save


Author
Message
Terry Bottorff
Terry Bottorff
Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)
Group: Forum Members
Posts: 448, Visits: 12K
That was it. Thank you very very much. The help here is excellant.Smile
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
Terry, the reason that you are getting the error is answered in Edhy's post.  You will have to set the BO properties on the BO to allow the primary key field to be updated.  This is the same approach that you would take if you were using GUIDs.
Peter Jones
Peter Jones
Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)
Group: Forum Members
Posts: 386, Visits: 2.1K
Hi Terry,

Just a comment re 'not wanting the PK to get bigger and bigger'. I presume you a using SQL Server in which case you can be assured it can handle the load unless you have an enormous insert rate, e.g. 1 per second for 10 years would only get your Identity column up to about the 300 million mark - 'easy as' for SQL Server.

Given that the PK is being 'reset' so regularly I can't imagine it has any interest to the user but, if it has, I would recommend adding another column for that use and simply let SQL take care of the PK.

Cheers, Peter

Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Terry,

If you want to manage your own PK updates you have to set the following BO properties:

  • PrimaryKeyIsAutoIncremented = False
  • PrimaryKeyIsUpdatable = True

Then in the BO_SetDefaultValues() or somewhere else in your code update the PrimaryKey field value.

Edhy Rijo

Terry Bottorff
Terry Bottorff
Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)
Group: Forum Members
Posts: 448, Visits: 12K

The same error that I reported previous.

Terry Bottorff
Terry Bottorff
Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)
Group: Forum Members
Posts: 448, Visits: 12K
Yes swst_pk is my primary key. The reason I don't have it as an identity is because the table get's rewritten 3 times a day with completely new data and I did not want the primary key to get bigger and bigger and bigger even though that probably is not a good reason. I manage it with an array of the same numbers and the only thing that chages is the stock field.

Thank you for the error code I will try it and report back. Thanks again.

Marcia G Akins
Marcia G Akins
StrataFrame User (496 reputation)StrataFrame User (496 reputation)StrataFrame User (496 reputation)StrataFrame User (496 reputation)StrataFrame User (496 reputation)StrataFrame User (496 reputation)StrataFrame User (496 reputation)StrataFrame User (496 reputation)StrataFrame User (496 reputation)
Group: StrataFrame Users
Posts: 322, Visits: 529
Terry Bottorff (01/31/2009)
Cannot insert the value NULL into column 'swst_pk', table 'ProRodeo.dbo.SWStocks'; column does not allow nulls. INSERT fails.
The statement has been terminated.

I get the above error when I try the following code?

SwStockBO1.NewRow()

SwStockBO1.swst_pk = 1

SwStockBO1.stock = 1000

' Save New Record

If SwStockBO1.Save() <> MicroFour.StrataFrame.Data.SaveUndoResult.Success Then

MsgBox("Save New Record Failed")

End If

I'm a newbie so what am I missing? TIA.

Is your data in SQL Server? Is swst_pk defined as a primary key? Why don't you just set it up as an identity column and use code like this:

SwStockBO1.Add();

SwStockBO1.stock = 1000;

Try

{

   SwStockBO1.Save();

}

Catch ( Exception loErr )

{

MicroFour.StrataFrame.Messaging.MessageForm.ShowMessage("Trinity Contact Management", loErr.Message.ToString(), "00000", MessageFunction.OK, MessagingIcon.Information, MessagingSounds.None);

}

If your primary key is an identity, you will not have these problems because SQL Server automagically takes care of generating it for you.

Terry Bottorff
Terry Bottorff
Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)
Group: Forum Members
Posts: 448, Visits: 12K
PS.

The table has only 2 fields. swst_pk, and stock. Both are integer and don't allow nulls.

I also tried playing with Return Alternate on Null in the BO Mapper but could not get that working. Also, played with AllowNullValueonNewRow in the properties using both True and False and did not get that to work either. My version of SF is 1.6.6.0

Terry Bottorff
Terry Bottorff
Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)
Group: Forum Members
Posts: 448, Visits: 12K
Cannot insert the value NULL into column 'swst_pk', table 'ProRodeo.dbo.SWStocks'; column does not allow nulls. INSERT fails.
The statement has been terminated.

I get the above error when I try the following code?

SwStockBO1.NewRow()

SwStockBO1.swst_pk = 1

SwStockBO1.stock = 1000

' Save New Record

If SwStockBO1.Save() <> MicroFour.StrataFrame.Data.SaveUndoResult.Success Then

MsgBox("Save New Record Failed")

End If

I'm a newbie so what am I missing? TIA.

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