Add a new table/row programmatically


Author
Message
Gerhard Jaros
Gerhard Jaros
StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)
Group: Forum Members
Posts: 18, Visits: 22
There is nothing in my DataSourceKey property, and if I insert data manually (with my StrataFrame form where I use the same BO) it works perfectly Smile It just doesn't work if I call the Save() method programmatically.
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
I bet your BO is not dirty when you are copying over the data.  Look at the IsDirty property after you call the CopyDataFrom method. 

MyBO.IsDirty

If it is false, then this is your problem.  You need to place the BO in an edit state before copying the data into it. 

Basically, all ADO.NET data rows have a RowState that indicates whether or not the row is dirty and needs to be saved.  More than likely your data table has already accepted the changes which will not force a save.  You can force each row to dirty by doing the following:

loBO.CopyDataFrom(MyDataTable, MicroFour.StrataFrame.Business.BusinessCloneDataType.ClearAndFillFromDefaultView)

If loBO.MoveFirst() Then
    Do
        '-- Force a new record to be created when saved
        loBO.CurrentRow.SetAdded()
    Loop While loBO.MoveNext()
End If

loBO.Save()

Gerhard Jaros
Gerhard Jaros
StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)
Group: Forum Members
Posts: 18, Visits: 22
Trent L. Taylor (10/30/2006)
I bet your BO is not dirty when you are copying over the data. 

You won the bet BigGrin

The Copy command works fine now, there just happend one simple thing which you could maybe tell me: I have a myBO.Clear() command in the same procedure - why does this one not set myBO.IsDirty to true? Right now all the existing rows are kept and the new rows coming in from CopyTableFrom are added, and the reason is that

myBO.Clear();
myBO.Save();

doesn't work because the isDirty prop is set to false. And I couldn't find a SetDeleted() method (like the SetAdded() method before).

Thanks for your help!

Gerhard Jaros
Gerhard Jaros
StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)StrataFrame Beginner (24 reputation)
Group: Forum Members
Posts: 18, Visits: 22
Do you maybe have an answer to my question? I meanwhile tried all kinds of different delete events and they also do not set the isDirty prop to true.

Thank you very much!

...gerhard...

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
I don't know what you are trying to accomplish.  The Clear removes any of the data within the BO and resets any flags.  Calling a Clear() and then a Save() would do literally nothing.  What are you trying to accomplish?

Just so you can better understand this, run this code:

MyBO.Clear()

MsgBox(MyBO.Count.ToString())

You will get a message box with a "0" in it.  There are no records in the BO after you call a clear...the records are not deleted, the BO is just cleared of its data.  If you want to delete all of the records in the BO, the easiest thing to do is enumerate and get all of the PKs then delete all of the PKs at once:

Dim loPKs As New System.Collections.Generics.List(Of Integer)

If MyBO.MoveFirst()
    Do
         loPKs.Add(MyBO.MyPrimaryKey)
    Loop While MyBO.MoveNext()
End If

'-- Now delete the records
For Each lnPK As Integer IN laPKs.ToArray()
    MyBO.DeleteByPrimaryKey(lnPK)
Next

You don't need to call the save because the DeleteByPrimaryKey immediately deletes the record on the server.

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