What is wrong with this please? :

  • Thread starter Thread starter trint
  • Start date Start date
T

trint

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
 
It looks like you have a required field for that table that hasn't been
populated.

James
 
Ok,
I included the createddatetime field this time and the error went on to
another field:
"Cannot insert the value NULL into column 'TravelEventId', table
'tsNess.dbo.tblTravelDetail'; column does not allow nulls. INSERT
fails."
Thanks,
Trint

..Net programmer
(e-mail address removed)
 
You need to give values to ALL columns that do not support NULL values

take a look at the table definition and you will know which fields are
those.


cheerrs,
 
The TravelDetailID is what I need automatically generated...Now the
error is saying the same for that field and it MUST be an identity
field. Why am I getting this error from column to column please? The
'Not Null'? If so, what value must my IDENTITY field be?
 
What can I do about the one that sql administrator said must be
autovalue and it is 'not null'.
Thanks,
Trint
 
First, I would make this a Parameterized Query to avoid SQL Injection
attacks. Barring that, try this:

string strSQL2 = "INSERT INTO " +
" tblTravelDetail (MemberID, CreatedDateTime) " +
"VALUES ('" + TxtMLV.Text.Trim() + "', " +
"'" + DateTime.Now.ToString() + "'); " +
"SELECT SCOPE_IDENTITY(); ";

Basically make sure you're quoting the CreatedDateTime value and putting a
semicolon between the INSERT and SELECT statements.
 
Hi,


If it's is autonumber then you cannot provide a value for it, it will be
assigned by the engine when you insert the row.


cheers,
 
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
 
Thanks for all of your help...I must finish another project by the end
of this week, then back on this...You guys are really great!
Trint

.Net programmer
(e-mail address removed)
 
Back
Top