17 Answers, 1 is accepted
Do you use this service directly or the grid is bound to DomainDataSource? Either way you need to call SubmitChanges() for the domain context in order to tell the service to persists changes in data-base.
Regards,
Vlad
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Thanks for the response. Here I am doing like this.
1. I am having a Grid Control in .xaml page.
2. I am having a Service in DAL.
3. I am binding a grid control like this.
VendorContext
objVndorCntxt = new VendorContext();
grdProducts.ItemsSource = objVndorCntxt.Vendors;
objVndorCntxt.LoadVendor();
4. In a grdProducts_AddingNewDataItem event I am adding a new row to the grid control.
5. In btnDelete_Click event I have to delete the selected row from the grid.
private
void btnDelete_Click(object sender, RoutedEventArgs e)
{
Vendor currentVendor = this.grdProducts.CurrentItem as Vendor;
VendorContext _context = new VendorContext();
if (currentVendor != null)
{
}
}
6. In btnSaveData_Click event I have to write a code to save the newly added row data in to DB.
private
void btnSaveData_Click(object sender, RoutedEventArgs e)
{
}
7. In OnEditRowUpdate event I am trying to update the edited row data in to DB.
private
void OnEditRowUpdate(object sender, GridViewRowEditEndedEventArgs e)
{
Vendor newVendor = e.NewData as Vendor;
if (newVendor != null)
{
VendorContext objCntxt = new VendorContext();
objCntxt.SubmitChanges();
}
}
These above steps I have written in my .CS file. Can you please help me on this.
Thanks In advance for your time.
Regards
Satish
I've attached small example using our latest binaries to illustrate you how to achieve your goal.
Regards,
Vlad
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Thanks a lot for the prompt response.
I tried to test the following code. Here I am getting the following exception (context.Products.Remove(toDelete);).
"The specified entity is not contained within this list."
" at System.Windows.Ria.Data.EntityList.Remove(Entity entity)\r\n at System.Windows.Ria.Data.EntityList`1.Remove(TEntity entity)\r\n at SilverlightGrid.MainPage.Button_Click_1(Object sender, RoutedEventArgs e)\r\n at System.Windows.Controls.Primitives.ButtonBase.OnClick()\r\n at System.Windows.Controls.Button.OnClick()\r\n at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)\r\n at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)\r\n at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)"
Please kindly help me on this. What will be the problem.
Thanks & Kind Regards
Satish
Do you have any inserted or edited item before this delete attempt? Please check this thread for more info:
http://silverlight.net/forums/t/84303.aspx
Kind regards,
Vlad
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Once again Thanks for the response.
Yes, I am inserting one row and I am trying to remove the same row from the grid. Then only I am getting this error.
One more thing i want to bring to your notice. Is it like the attached code is not having functionality for updating the row.
And I am using ADO.NET EntityDatamodel for database connectivity. How can I declare this in my App.
((IEditableCollectionView)northwindData.DataView).CommitEdit(); -- I think here they are using Northwind.dbml to connect DB.
((IEditableCollectionView)northwindData.DataView).CommitNew(); -- I think here they are using Northwind.dbml to connect DB.
((IEditableCollectionView)northwindData.DataView).Remove(usr); -- I think here they are using Northwind.dbml to connect DB.
Please kindly help me how to do the same in my case.
Ahead of you for your response.
Thanks & Kind Regards
Satish
I've attached new project with RadGridView for Silverlight 3 insert, update and delete functionality and DomainService with ADO.NET Entities.
Best wishes,
Vlad
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
You are really rocking.......
I am glad with your response. Thanks a lot.
One more thing I have noticed in this code is like, it's deleting in the context but not in DB. Could you please look in to this.
I appreciate your time.
Thanks & Kind Regards
Satish
If you call SubmitChanges() the record will be deleted from the data-base also.
Regards,
Vlad
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
I am doing the same but it's not deleting from the DB.
Please find the below code.
private
void Button_Click_1(object sender, RoutedEventArgs e)
{
Products toDelete = (Products)((Button)sender).ParentOfType<GridViewRow>().DataContext;
if (service.Products.Contains<Products>(toDelete))
{
service.Products.Remove(toDelete);
service.SubmitChanges();
}
}
Kind Regards,
Satish
Could you please help me on this. I can't able to find the solution for this.
Regards,
Satish
Can anybody please help me on this. This is very urgent deliverable.
A head of you for your response.
Thanks In advance for your time.
Thanks & Regards
Satish
Looks like there is a problem with Products table from Northwind in my example. I've attached modified version of the example with custom data base where deletes will work as expected.
Kind regards,
Vlad
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Thanks alot for the response.
I am using the same code in my Solution.
Here the code :
private void btnDelete_Click(object sender, RoutedEventArgs e) |
{ |
#region "CODE FOR SELECTED ROW DELETION" |
Vendor toDelete = (Vendor)((Button)sender).ParentOfType<GridViewRow>().DataContext; |
if (toDelete != null) |
{ |
DomainDataSource objDomainDataSource = new DomainDataSource(); |
objDomainDataSource.DomainContext = objVendorContext; |
((IEditableCollectionView)objDomainDataSource.DataView).CommitEdit(); |
((IEditableCollectionView)objDomainDataSource.DataView).CommitNew(); |
((IEditableCollectionView)objDomainDataSource.DataView).Remove(toDelete); |
objVendorContext = ((VendorContext)objDomainDataSource.DomainContext); |
objVendorContext.Vendors.Remove(toDelete); |
} |
#endregion |
} private
void btnSubmitChanges_Click(object sender, RoutedEventArgs e)
{ objVendorContext.SubmitChanges(); } |
SubmitChanges() is calling the below method from DomainService (VendorService).
public void DeleteVendor(Vendor vendor) |
{ |
if ((vendor.EntityState == EntityState.Detached)) |
{ |
this.Context.Attach(vendor); |
} |
this.Context.DeleteObject(vendor); |
} |
I am Using AdvaceWork DB (Table is Vendor). If possible could you please let me know what will be the problem.
I appreciate your valuable time.
If possible could you please let me know the Update process also.
Thanks & Kind Regards
Satish
I've found that when you try to remove record the EF will throw an exception exactly the same to this one:
http://silverlight.net/forums/t/98938.aspx
You can observe this if you handle Submitted event:
void service_Submitted(object sender, System.Windows.Ria.Data.SubmittedChangesEventArgs e)
{
if (e.Error != null)
{
///
}
}
I believe that this is one of the current issues in RIA services - probably related to SQL Server version (in my case SQL Express 2005)
Kind regards,
Vlad
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Thanks for the response. Do we have any other alternate way to resolve this problem.
Regards
Satish
Unfortunately I'm not aware of such - you can ask for more info on MS RIA forums.
Sincerely yours,
Vlad
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.