473,396 Members | 1,915 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

What is wrong with this please? :

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

Nov 17 '05 #1
10 1218
It looks like you have a required field for that table that hasn't been
populated.

James

"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

Nov 17 '05 #2
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
tr***********@gmail.com

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #3
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,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"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

Nov 17 '05 #4
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?

Nov 17 '05 #5
What can I do about the one that sql administrator said must be
autovalue and it is 'not null'.
Thanks,
Trint

Ignacio Machin ( .NET/ C# MVP ) wrote:
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,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"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


Nov 17 '05 #6
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.
> string strSQL2 = "INSERT INTO tblTravelDetail(MemberID) " +
> "VALUES ('" + TxtMLV.Text.Trim() + "')" +
> "SELECT @@IDENTITY " ;
>
> cnn2.Execute(strSQL2, out recordsEffected, 0);

Nov 17 '05 #7
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,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"trint" <tr***********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
What can I do about the one that sql administrator said must be
autovalue and it is 'not null'.
Thanks,
Trint

Ignacio Machin ( .NET/ C# MVP ) wrote:
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,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

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

Nov 17 '05 #8
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

Nov 17 '05 #9
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
tr***********@gmail.com

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #10

Make sure the autonumber column in your table is set as the Primary Key.
*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: What-a-Tool | last post by:
I'm going out out of my mind trying to get this to work with no luck. The error message I get is at the bottom. Can someone please tell me what I'm doing wrong here. I've tried this a million...
125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
72
by: E. Robert Tisdale | last post by:
What makes a good C/C++ programmer? Would you be surprised if I told you that it has almost nothing to do with your knowledge of C or C++? There isn't much difference in productivity, for...
17
by: Paul | last post by:
HI! I get an error with this code. <SCRIPT language="JavaScript"> If (ifp==""){ ifp="default.htm"} //--></SCRIPT> Basicly I want my iframe to have a default page if the user enters in...
33
by: bissatch | last post by:
Hi, I fully understand the purpose of an alt attribute within a <img> tag but why would you use a title or summary attribute within, for example, a <p> tag. I have read books recommending that I...
2
by: Aaron Ackerman | last post by:
I cannot a row to this bound DataGrid to SAVE MY LIFE! I have tried everything and I am at a loss. The using goes into add mode with the add button adds his data then updates with the update...
7
by: arun_shamli | last post by:
class CDate { public: CDate() {} CDate(const CDate& date) {} }; CDate function1() { CDate date(); return date;
3
by: belton180 | last post by:
CODE]../* Program function: Simulate the stack using a stack limit of 10. Display a menu for the the following. Create a stack Insert an item in the stack Pop an item from the stack ...
2
by: jakeruston | last post by:
Hi, I have coded this and it is coming up with hundreds of errors. What is wrong with this anyway? #include <iostream> #include <string> using namespace std; using std::cout;
3
by: redcodeheaven | last post by:
Hello my teacher gave me an exercise to enter my name and 2 numbers the output must show the sum and the product of these 2 numbers and keep repeating the same procedure using a while loop till i...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.