2

I am populating a datagrid with a dataset and I have my dataset verified for nullable values -

My problem is :

When the dataset is validating, it found empty rows and the errors are not displayed. I would like to define the empty cells with a DBNull.value. Is there any way to do it ?. I have found a property named TargetNullValue that could work ?

3
  • Empty rows or Empty columns ? Commented Jun 28, 2012 at 15:00
  • Empty cells I meand when the datagrid is populated and some field has empty string as value Commented Jun 28, 2012 at 16:28
  • Why don't you add IS_NULL in your SQL such that those fields then become bindable - msdn.microsoft.com/en-us/library/ms184325.aspx Commented Jun 28, 2012 at 16:34

1 Answer 1

2

I found a way to do it, by making a convertion

 public class ConvertStringToDBNull : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo cufo)
    {

        if (value is string)
        {
            if (value.ToString() == string.Empty)
            {
                return DBNull.Value;
            }
        }
        return value;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo cufo)
    {

        if (value is string)
        {
            if (value.ToString() == string.Empty)
            {
                return DBNull.Value;
            }
        }
        return value;
    }

}
Sign up to request clarification or add additional context in comments.

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.