views:

29

answers:

1

I need to do some simple (or so it seems) databinding and CRUD type operations on an ASP.Net page. I'm using a LinqDataSource connected with a FormView. The table that i'm trying to insert into has default contraints for these fields:

[Created] [datetime] NOT NULL
[CreatedBy] [nvarchar](50) NOT NULL
[Modified] [datetime] NOT NULL
[ModifiedBy] [nvarchar](50) NOT NULL

ALTER TABLE [dbo].SolutionComponent ADD  CONSTRAINT [DF_SolutionComponent_Created]  DEFAULT (getdate()) FOR [Created];
ALTER TABLE [dbo].SolutionComponent ADD  CONSTRAINT [DF_SolutionComponent_CreatedBy]  DEFAULT (suser_sname()) FOR [CreatedBy];
ALTER TABLE [dbo].SolutionComponent ADD  CONSTRAINT [DF_SolutionComponent_Modified]  DEFAULT (getdate()) FOR [Modified];
ALTER TABLE [dbo].SolutionComponent ADD  CONSTRAINT [DF_SolutionComponent_ModifiedBy]  DEFAULT (suser_sname()) FOR [ModifiedBy];

When doing an insert i'm getting a SQL Datetime overflow error because it's trying to insert a value into Created and Modified even though I have not bound anything to these fields.

My question is how can I get the LinqDataSource to omit these fields in the insert statement or at least supply dbnull or null to allow database level defaults to take over?

A: 

I might not be reading your question correctly, but if the constraints do not allow NULL values it's not going to work.

James Smith
@James - Thanks, i've updated my post with code that shows which defaults are on the table. The idea is that supplying a null to those columns in the insert statement will allow the defaults to take over. I need to know how to tell the LinqDataSource to pass dbnull to these columns.
James
I found this article and it sounds similar to your issue. http://www.codeproject.com/KB/linq/SettingDefaultValues.aspx.
James Smith