Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
h have gridview1 that contain RepositoryItemLookUpEdit columnto make user choose items :
column Field name : stitems_ID (int(11))
RepositoryItemLookUpEdit Display Member : Name (varchar(255))
RepositoryItemLookUpEdit Value Member : stitems_ID (int(11))

st_itemsBindingSource.DataSource = Context.st_items.Local.ToBindingList();



gridview1 filled with data as : succeed

C#
purchases_itemBindingSource1.DataSource = Context.purchases_item.Where(u => u.pmain_ID == PurchasesID).ToList();


i used Entity framework to insert / update / select ..

insert operation: succeed

for (int ItemImdex = 0; ItemImdex < gridView1.DataRowCount; ++ItemImdex)
               {

                   purchases_item purchasesItem = new purchases_item();
                   purchasesItem.pmain_ID = lastid;
                   purchasesItem.stitems_ID = Convert.ToInt32(gridView1.GetRowCellValue(ItemImdex, "stitems_ID"));
                    .........

                   Context.purchases_item.Add(purchasesItem);
                   Context.SaveChanges();
               }


Update operation: failed
data loaded from mysql database to gridview successfully and right value appear in repositoryitemlookupedit , but during the update operation
C#
Convert.ToInt32(gridView1.GetRowCellValue(ItemImdex, "stitems_ID"))
return zero value not the selected value.

What I have tried:

gridview1 filled with data as : succeed
purchases_itemBindingSource1.DataSource = Context.purchases_item.Where(u => u.pmain_ID == PurchasesID).ToList();
Posted
Updated 6-Feb-18 8:28am
v2
Comments
johannesnestler 6-Feb-18 13:32pm    
so what was the exception? btw. you can call SaveChanges outside the Loop - so you don't talk x-times to the database during Looping...
Golden Basim 6-Feb-18 14:26pm    
data loaded from mysql database to gridview successfully and right value appear in repositoryitemlookupedit , but during the update operation Convert.ToInt32(gridView1.GetRowCellValue(ItemImdex, "stitems_ID")) return zero value not the selected value.
Richard MacCutchan 6-Feb-18 15:14pm    
Use your debugger to step into that line of code to find out why. Most likely some object reference, or index, is invalid.
Golden Basim 6-Feb-18 17:04pm    
by using this steps i found the value of "a" in the first line = 1500 (correct value)
but the last is empty. ( i use the this code to remove old items data)
a = "";
for (int i = 0; i < gridView1.DataRowCount; ++i)
{
a = Convert.ToString(gridView1.GetRowCellValue(i, "stitems_ID")) + " / ";
}
// remove Old Items
Context.purchases_item.RemoveRange(Context.purchases_item.Where(u => u.pmain_ID == PurchasesID));
Context.SaveChanges();
//// remove Old Serials
Context.purchases_item_seriels.RemoveRange(Context.purchases_item_seriels.Where(u => u.pmain_ID == PurchasesID));
Context.SaveChanges();
a = "";
for (int i = 0; i < gridView1.DataRowCount; ++i)
{
a = Convert.ToString(gridView1.GetRowCellValue(i, "stitems_ID")) + " / ";
}
Golden Basim 6-Feb-18 17:16pm    
it seam that the error here
//Context.purchases_item.RemoveRange(Context.purchases_item.Where(u => u.pmain_ID == PurchasesID));
//Context.SaveChanges();
but i don't know what is ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900