datagridview with entity framework delete data

by Tarenk 77   Last Updated May 23, 2020 00:26 AM

Hi I am using a datagridview with Entity Framework and when I click on the cell, the program ends its execution and does not delete the record, Error: System.FormatException: 'The input string is not formatted correctly'

Check this: int CasaId = Convert.ToInt32(dataGridView1.CurrentRow.Cells[2].Value.ToString());

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e){

                using (var context = new AppDbContext())
                {

                   int HomeId = Convert.ToInt32(dataGridView1.CurrentRow.Cells[2].Value.ToString());

                    var Home = new home();
                    Home.homeId = HomeId;
                    context.Entry(Home).State = EntityState.Deleted;
                    context.SaveChanges();


                }




        }
Tags : c# forms entity


Related Questions


symfony 3 form entity returning converting error

Updated March 13, 2017 10:26 AM

Symfony - perist multiple entities

Updated October 01, 2018 09:26 AM


Symfony CollectionType with no entity

Updated October 19, 2017 17:26 PM

Editing entity - choicetype are reset

Updated November 07, 2017 10:26 AM