2

I am having one integer column in a data table and I want to set null value in that column. I have done AllowDBNull true but still it doesn't work if a null value is getting added.

Following are the configuration which I have done for Column

enter image description here

I am getting following exception enter image description here

Can anyone help mi for this?

1
  • Please, provide textual representation of error. Some of use can't see images. Commented Sep 22, 2016 at 6:58

5 Answers 5

3

You can't assign DBNull to a field in the DataTable. When you allow DBNull in a DataTable, an extra method is generated. In this case: SetParentApplicationRoleIdNull()

for example:

var newRow = DataSet.ChildApplications.NewChildApplicationRow();
newRow.AField = "Some text";
newRow.SetParentApplicationRoleIdNull();
DataSet.ChildApplications.AddChildApplicationRow(newRow);

This is also while checking the value. You can't directly use the 'property' ParentApplicationRoleId, If you want to read it, you'll have the check it first with another generated method: IsParentApplicationRoleIdNull()

for example:

foreach(var row in DataSet.ChildApplications.Rows)
{
    if(!row.IsParentApplicationRoleIdNull())
    {
        Trace.WriteLine($"ParentApplicationRoleId: {row.ParentApplicationRoleId}");
    }
    else
    {
        Trace.WriteLine("ParentApplicationRoleId: is DBNull, and can't be shown");
  }
}
Sign up to request clarification or add additional context in comments.

Comments

0

The "?" behind a datatype makes it nullable.

Example:

int? t = null; 

So nzrytmn is right!

Comments

0

You can try setting the NullValue property of the data column to something that is not "(ThrowException)"

Comments

0

Did you try set DataType as Sytem.Int32? May it have to be nullable.

Could you pls check this answer Table is nullable DateTime, but DataSet throws an exception?

Comments

-2

Please declare that value as nullable int(int?). then it will accet all null values

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.