Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AllowDBNull

Status
Not open for further replies.

Strannik

Programmer
Jul 4, 2002
132
UA
Did anybody deal with such ADO behavior ?
I have MSSQL table with some NOT NULL columns. When I retrieve AllowDBNull property for these columns each column has AllowDBNull = true.
Any ideas ?
 
The AllowDBNull property is used to indicate whether null values are allowed in this column for rows belonging to the table (DataTable object) and not to data source table.
When you create a DataTable object , the default value of AllowDBNull is true and it is not related with the NOT NULL of the data source.
You should set it manually, to false for that columns.
In the DataTable object, database null e.g. the constant representing a database column absent of data is Convert.DBNull.
DataTable myTable = new DataTable();
myTable.AllowDBNull = false; // to be sure that what you will modify or add in DataTable object is not set to null database.
myTable["column"]=Convert.DBNull; // set null
-obislavu-
 
OK

Then how to determine that specific column cannot be NULL(using ADO.NET) ?
 
Query the data source for the columns you are interested to know e.g. send a query like that:
Code:
select COLUMNPROPERTY(OBJECT_ID('_tSummary'), 'firstname','AllowsNull')as b1, COLUMNPROPERTY(OBJECT_ID('_tSummary'), 'amount','AllowsNull')as b2 from _tSummary
In the above example returns b1 and b2 as boolean :
b1 b2
-- --
0 1
0 1
0 1
because the firstname does not allows null but amount allows null.
You can retrieve that info about the all tables and columns you want in one single query.
-obislavu-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top