SaveEntity - SQL-Server

Posts   
 
    
Slowhand
User
Posts: 96
Joined: 07-Mar-2006
# Posted on: 09-Mar-2006 11:59:22   

Hello, I´m having problems when I save back values from a grid to an SQL-Server:

In my class I define as member:


SQLEXPRESS.HelperClasses.EntityCollection    filteredName = new SQLEXPRESS.HelperClasses.EntityCollection(new TblnameEntityFactory());

// Read all values from the table in a datagrid

private void button4_Click(object sender, EventArgs e)
        {
        
            SQLEXPRESS.DatabaseSpecific.DataAccessAdapter adapter1 = 
                new SQLEXPRESS.DatabaseSpecific.DataAccessAdapter();        
            filteredName.Clear();
            adapter1.FetchEntityCollection(filteredName, null);
            dataGridView1.DataSource = filteredName;

            adapter1.Dispose();
        
        }

//now I change some values in the grid ... and click the save button:

private void button3_Click_1(object sender, EventArgs e)
{
TblnameEntity newName = new TblnameEntity();
SQLEXPRESS.DatabaseSpecific.DataAccessAdapter adaptername = new SQLEXPRESS.DatabaseSpecific.DataAccessAdapter();

            foreach (TblnameEntity tblname in filteredName)
                    adaptername.SaveEntity(tblname);

}

//When I make now a new selection to show data in the grid I see, that
//EVERY row has the value I gave only one row:
/*
My table has only 2 cols:
id and name which has those values

id  name
1   Name1
2   Name2

when I change Name1 to MyName, save it and make then a new select and show
the data on the grid and of course take a look at the table name in the database
all names has changed to MyName:

id   name
1   MyName
2   MyName

NOTE: When I do exactly the same on an Oracle System it works without any problem.
*/

Can you please tell me what´s wrong with my code ?

Thanks a lot, Slowhand

Walaa avatar
Walaa
Support Team
Posts: 14987
Joined: 21-Aug-2005
# Posted on: 09-Mar-2006 14:36:02   

Would you please place a break point inside the foreach loop in the button3_Click_1() method. And examine each entity before it's saved to see if it hold the data you would expect?!!

Why don't you use SaveEntityCollection() instead of Saving each Entity alone?

Slowhand
User
Posts: 96
Joined: 07-Mar-2006
# Posted on: 09-Mar-2006 16:25:59   

Walaa wrote:

Would you please place a break point inside the foreach loop in the button3_Click_1() method. And examine each entity before it's saved to see if it hold the data you would expect?!!

Why don't you use SaveEntityCollection() instead of Saving each Entity alone?

I´ve tried both ways with the same result. I´ve looked to every value of the entity and everything is ok but in the database there are the same values again, as I described it.

I have two values in my table:

id name 1 name1 2 name2

when I ONLY edit in the datagrid name2 and save it and look before and after saving to the entity I´ve got an OutOfSyncError when the foreach comes to the second run:



foreach (SQLDISPO.EntityClasses.DispoEntity de in filteredSQLDispos)
            {
                s = de.Rngnr;
                adaptersql.SaveEntity(de);
                s1 = de.Rngnr; // OutOfSyncError 
            
            }


Complete ErrorMessage:

_ SD.LLBLGen.Pro.ORMSupportClasses.ORMEntityOutOfSyncException wurde nicht behandelt. Message="The entity is out of sync with its data in the database. Refetch this entity before using this in-memory instance." Source="SD.LLBLGen.Pro.ORMSupportClasses.NET20" StackTrace: bei SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.GetCurrentFieldValue(Int32 fieldIndex) bei SQLDISPO.EntityClasses.DispoEntity.get_Rngnr() in D:\Test\WT\LLBLGen\DATABASE_PROJECT\SQLDISPO\DatabaseGeneric\EntityClasses\DispoEntity.cs:Zeile 4608. bei LLBLGen.Form1.button3_Click_1(Object sender, EventArgs e) in D:\Test\WT\LLBLGen\LLBLGen\Form1.cs:Zeile 127. bei System.Windows.Forms.Control.OnClick(EventArgs e) bei System.Windows.Forms.Button.OnClick(EventArgs e) bei System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) bei System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) bei System.Windows.Forms.Control.WndProc(Message& m) bei System.Windows.Forms.ButtonBase.WndProc(Message& m) bei System.Windows.Forms.Button.WndProc(Message& m) bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) bei System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) bei System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) bei System.Windows.Forms.Application.Run(Form mainForm) bei LLBLGen.Program.Main() in D:\Test\WT\LLBLGen\LLBLGen\Program.cs:Zeile 17. bei System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args) bei System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() bei System.Threading.ThreadHelper.ThreadStart_Context(Object state) bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) bei System.Threading.ThreadHelper.ThreadStart() _

Maybe it helps ?

Regards, Slowhand