The problem is not with your code, but, almost certainly, with the
definition of the table.
Most likely, it is defined as:
CREATE TABLE [dbo].[tblTravelDetail] (
[TravelEventId] [int] NOT NULL ,
[MemberID] [int] NOT NULL ,
-- Other stuff
[CreatedDateTime] [datetime] NOT NULL
)
When it really wants to be defined as :
CREATE TABLE [dbo].[tblTravelDetail] (
[TravelEventId] [int] IDENTITY (1, 1) NOT NULL ,
[MemberID] [int] NOT NULL ,
[CreatedDateTime] [datetime] NOT NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[tblTravelDetail] ADD
CONSTRAINT [DF_tblTravelDetail_CreatedDateTime] DEFAULT (getdate()) FOR
[CreatedDateTime]
GO
Have you recently transfered the table from one SQL server to another via
SQL scripts? Enterprise Manager's "Generate Scripts" command won't write
the default contrant unless you tell it to on the Options tab.
--
--
Truth,
James Curran
[erstwhile VC++ MVP]
Home:
www.noveltheory.com Work:
www.njtheater.com
Blog:
www.honestillusion.com Day Job:
www.partsearch.com
"trint" <tr***********@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
I've looked this over and just don't get why the error is "An unhandled
exception of type 'System.Runtime.InteropServices.COMException'
occurred in db2sql.exe
Additional information: Cannot insert the value NULL into column
'CreatedDateTime', table 'tsNess.dbo.tblTravelDetail'; column does not
allow nulls. INSERT fails."
This syntax, except for the @@identity, is exactly the same in my other
programs that work:
Object recordsEffected;
string strSQL2 = "INSERT INTO tblTravelDetail(MemberID) " +
"VALUES ('" + TxtMLV.Text.Trim() + "')" +
"SELECT @@IDENTITY " ;
cnn2.Execute(strSQL2, out recordsEffected, 0);
Thanks,
Trint