* Merge winforms framework content to working branch (#14) * Breadcrumb / TOC / Move net5 to net folder (#15) * change path from net5 to net * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Add .net 5 winforms placeholder article (#16) * added some metadata and adjusted net5 placeholder * corrections * corrections * corrections * Test1 * Swapping landing page vs concept * fix links * Fix links * Fix desc
2.2 KiB
title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
| title | ms.date | dev_langs | helpviewer_keywords | ms.assetid | |||||
|---|---|---|---|---|---|---|---|---|---|
| Bind Controls to DBNull Database Values | 03/30/2017 |
|
|
96494e6f-5f40-4f83-af97-bbd7192c2af8 |
How to: Bind Windows Forms Controls to DBNull Database Values
When you bind Windows Forms controls to a data source and the data source returns a xref:System.DBNull value, you can substitute an appropriate value without handling, formatting, or parsing events. The xref:System.Windows.Forms.Binding.NullValue%2A property will convert xref:System.DBNull to a specified object when formatting or parsing the data source values.
Example
The following example demonstrates how to bind a xref:System.DBNull value in two different situations. The first demonstrates how to set the xref:System.Windows.Forms.Binding.NullValue%2A for a string property; the second demonstrates how to set the xref:System.Windows.Forms.Binding.NullValue%2A for an image property.
[!code-csharpSystem.Windows.Forms.BindingDBNull#1] [!code-vbSystem.Windows.Forms.BindingDBNull#1]
The types of the bound property and the xref:System.Windows.Forms.Binding.NullValue%2A property must be the same or an error will result, and no further xref:System.Windows.Forms.Binding.NullValue%2A values will be processed. In this situation, an exception will not be thrown.
Compiling the Code
This example requires:
- References to the System, System.Data, System.Drawing and System.Windows.Forms assemblies.