HighTechTalks DotNet Forums  

Table Field Set To Not Allow Nulls

Dotnet Framework (ADO.net) microsoft.public.dotnet.framework.adonet


Discuss Table Field Set To Not Allow Nulls in the Dotnet Framework (ADO.net) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
JimHeavey
 
Posts: n/a

Default Table Field Set To Not Allow Nulls - 11-21-2007 , 11:12 AM






I have a table with 2 keys, which are of course identified as not being
allowed to be null. I have created a screen in which has a number of fields
identified for selection criteria, and the user has the freedom to identify
which fields it will use to make their selection on. Sometimes they will
enter criteria for the key fields and sometimes they will not.

I have use VS2005 to generate my dataset and my dataAdapter. I have bound
the data adapter to a DataView and bound the selection criteria to the text
boxes on the web form. The problem is when the user does not specify any
criteria for the "key" fields which can not be null, an execption is thrown
for the key field which is blank telling me the key field can not be null.
How do I get around this?

Reply With Quote
  #2  
Old   
Brad Roberts
 
Posts: n/a

Default RE: Table Field Set To Not Allow Nulls - 11-21-2007 , 03:12 PM






I have encountered something like this before. Unfortunately, the default
values for the SQL tables are not propogating to the dataset with the
SelectCommand.

My work-around was as follows. I hope I can explain it clearly enough in
relatively few words.

Immediately after the DataSet has been created, before the DataAdapter has
been used to fill a DataTable with data, run the Select query once to get the
schema of the query results into the dataset/datatable.

example,

SQLDataAdapter.SelectCommand = cmd
SQLDataAdapter.FillSchema(ADataset, SchemaType.Source, "ResultsTable")

then something like....

Dim df As DataColumn
For Each df In ADataset.Tables("ResultsTable").Columns
df.AllowDBNull = True
If df.ColumnName = "MyColumnName" Then
df.DefaultValue = ""
End If
Next

--With the schema in place before the SelectCommand is executed the results
will go into the previously defined DataTable, which has a default value for
the field that is not to have a null.

--Then something like
SQLDataAdapter.Fill(ADataset, "ResultsTable")




--
Brad

"Software is like melted pudding..."




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.