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..." |