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

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -