PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 1.00 average.

DataTable with Column Default Values not working as execpted

 
 
William F. Kinsley
Guest
Posts: n/a
 
      22nd Dec 2005
I was having a problem using a DataTable targeted against a table with
columns that have default values and do not allow nulls. When you added a
new row to the DataTable, and call Update on the adapter. It uses the
CommandBuilder to build the insert against the table. This insert has the
column set to null, which will fail, because the column does not allow
nulls. If I fill in the default value property on the datatable column, it
uses the default value instead of null and everything is happy.

This brings me to question #1) Is there a way to fill datatable schema
information that includes the default value automatically? The
missingschemaaction stuff does not seem to do the job.

So I added a manual schema fill for default values and everything works fine
for columns with static default values, but I still have a problem with
default values that are functions such as (getdate()) on a date time column
for instance. In my current model, the default value comes back from the
schema information as (getdate()), which I then try to set as the default
value of the column. This however causes an exception because of course
(getdate()) can not be translated into a date by the datatable. For legal
reasons the sql server must create this date when the row is added. I can
not create a new date in code and set that as the default value.

This brings me to question #2) Is there a way to use function default
values with a datatable.


 
Reply With Quote
 
 
 
 
Kevin Yu [MSFT]
Guest
Posts: n/a
 
      23rd Dec 2005
Hi William,

1. The default value information will not be filled to the schema from the
database structure automatically. This is by design. So we have to do this
manually in the schema designer.

2. DataColumn default values don't support functions. So I think you have
to leave the fieldfor database to generate.

Since the CommandBuilder does not support this, we have to write our own
update,insert and delete command.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Datatable default values Vik Microsoft ASP .NET 1 25th Feb 2006 04:15 AM
Get distinct values from a column in a datatable jvb Microsoft VB .NET 2 30th Jan 2006 08:12 PM
Sum 3 column values in a DataTable Codex Twin Microsoft ADO .NET 1 1st Nov 2005 03:56 PM
Set column values in a DataTable all at once? nate axtell Microsoft VB .NET 1 17th Aug 2005 02:59 PM
DataTable Column values gpertea@gmail.com Microsoft ADO .NET 9 14th Dec 2004 03:17 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:17 PM.