c# - Insert empty value from datagridview -



c# - Insert empty value from datagridview -

i trying insert empty value datagridview when cell left empty. i'm doing:

using (var context = new employeeentities()) { employee emp= new employee (); foreach (datagridviewrow row in dgvloadtable.rows) { if (row.cells[0].value != null) { emp.emp_id = int.parse(row.cells[0].value.tostring()); emp.department = row.cells[2].value dbnull ? string.empty : row.cells[2].value.tostring(); //also tried: emp.department = row.cells[2].value dbnull ? dbnull.value.tostring() : row.cells[2].value.tostring(); context.employee.addobject(emp); context.savechanges(); } } }

but it's not working, when seek insert null value throws "object reference not set instance of object" exception. doing wrong here?

c# entity-framework datagridview

Comments

Popular posts from this blog

maven fortify plugin : Unable to load build session with ID XXXXX .. See log file for more details -

c# - Primavera WebServices does not return any data -

android - Display emoji panel with genymotion - keyboard/touch input? -