Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
140
deleting records using Linq
posted

Hi, I am developing a WPF browser application using Linq and your datagrid but I am having major problems trying to delete a record. From looking through various forums and your help I have got to the point where I can retrieve the data usning LINQ and settign the result as the DataSource. I can add a record fine but whenit comes to deleteing I just cant seem to tie it togther. A number of forums have suggesed that once you know what records you need to delete you query it from teh database using LINQ then plase the result into a DeleteOnSubmit command. So I have the following code:

        private void datagridMapping_RecordsDeleting(object sender, Infragistics.Windows.DataPresenter.Events.RecordsDeletingEventArgs e)

        {

            DataCentreDataContext dsMapping = new DataCentreDataContext();

 

            foreach (var rec in datagridMapping.SelectedItems.Records)

            {

                try

                {

                    var mappingres =

                        from mappingItem in dsMapping.DATAMAPPINGs

                        where mappingItem.INDEX == rec.???????????????

                        select mappingItem;

 

                    DATAMAPPING delRecord = new DATAMAPPING();

                    delRecord = (DATAMAPPING)mappingres;

 

                    dsMapping.DATAMAPPINGs.DeleteOnSubmit(delRecord);

                }

                catch (Exception ex)

                {

                    MessageBox.Show("Error", "Error - " + ex.Message);

                }

 

            }

           

            dsMapping.SubmitChanges();

        }

I have placed ?????? where I am having the trouble. I guess I may have this very wrong so any help would be very much appreciated.

Regards,

Kevin.