Windows Develop Bookmark and Share   
 index > Windows Forms Sample Applications > Working with DataGridView. I have an Exception as "Column 'Column' does not allow nulls."
 

Working with DataGridView. I have an Exception as "Column 'Column' does not allow nulls."

Opening a form that has DataGridView for Insert new record. I edit one cell in it and press Esc, it throw a Exception as "Column 'Column' does not allow nulls."
( DataGridView using TableAdapter, BidingSource, DataSet as Datasource of DGV - use wizard to add datasource for DGV )
Someone can tell me what it is ?? and how to handle this Exception ????

Thank you

Jerry_lth  Monday, November 05, 2007 7:27 AM

Hi Jerry_lth,

I believe that there is one or more column that does not allow null value. You can check it out by loop through all columns and check the AllowDBNull property. Try the following code:

Code Block

foreach (DataColumn col in dataset.Tables[0].Columns)

{

if (!col.AllowDBNull)

System.Console.WriteLine(col.ColumnName + " does not allow null value!");

}

Hope this helps.
Best regards.
Rong-Chun Zhang

Rong-Chun Zhang  Wednesday, November 07, 2007 1:08 PM

Hi Jerry_lth,

I believe that there is one or more column that does not allow null value. You can check it out by loop through all columns and check the AllowDBNull property. Try the following code:

Code Block

foreach (DataColumn col in dataset.Tables[0].Columns)

{

if (!col.AllowDBNull)

System.Console.WriteLine(col.ColumnName + " does not allow null value!");

}

Hope this helps.
Best regards.
Rong-Chun Zhang

Rong-Chun Zhang  Wednesday, November 07, 2007 1:08 PM

You can use google to search for other answers

Custom Search

More Threads

• Is there a standart control for "File, Edit, view, ..."?
• Outlook Calendar Look and Feel - Automatic refresh
• SAlesOrders SAmple
• taskvision cpntrol sources
• TaskVision and Replication
• about Icons of XPander
• Canadian Terrarium Contest
• Updating Data Bindings
• How did they do that?
• Insttal problems