I am trying to manually create a strongly typed data row
DataSet.PersonRow personRow;
personRow=dataset.Person.NewPersonARow();
personRow.MiddleName=(string)GridView.GetFocusedRowCell("Middlename");
Unable to cast object of type 'System.DBNull' to type 'System.String'. while saving in the database
Unable to cast object of type 'System.DBNull' to type 'System.String'. while saving in the database
4 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Kirtan PatelRank #292 · 8.6K reputationPosted Aug 17, 2009, 9:02 AM EDT
string s = System.DBNull.value.ToString();
Master BillaRank #2,229 · 630 reputationPosted Aug 17, 2009, 9:15 AM EDT
I think that coulmn is Null value,
so you need check like this way'
if(GridView.GetFocusedRowCell("Middlename") !-=null)
{
personRow.MiddleName=(string)GridView.GetFocusedRowCell("Middlename");
}
thank you
Desi Gal35 reputationPosted Aug 17, 2009, 9:24 AM EDT
still
GridView.GetFocusedRowCellValue("MiddleName")!=null gives me a null value in the Debug Mode
Desi Gal35 reputationPosted Aug 17, 2009, 9:45 AM EDT
GridView.GetFocusedRowCellValue("MiddleName") was returning me null inspite of having a valid value.
I trid the same code in the rowUpdated event and it works