473,322 Members | 1,287 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,322 software developers and data experts.

Cannot insert the value NULL

Hi All.

I'm trying to insert data into 2 tables (parent-child) using the ADO.NET's
SetParentRow method. The parent table has an identity column as primary key.
When I execute the code below I get the following message: "Cannot insert
the value NULL into column 'hdtID', table
'myinstance.mydb.Hotel_Details_Lang'; column does not allow nulls. INSERT
fails." Any idea?

PS: To create the DataAdapters, I'm using SqlCommandBuilder.

public void Insert_Hotel_Details(string hdtDescription) {
DataSet dsTemp = null;
try {
// Get the dataset with those two tables to use;
dsTemp = Get_Hotel_Details();

//Parent Table;
DataRow drwParent = dsTemp.Tables["Hotel_Details"].NewRow();
drwParent["hdtTemp"] = false;
dsTemp.Tables["Hotel_Details"].Rows.Add(drwParent);

//Child Table;
DataRow drwChild = dsTemp.Tables["Hotel_Details_Lang"].NewRow();
drwChild.SetParentRow(drwParent);
drwChild["lngID"] = 1;
drwChild["hdtDescription"] = hdtDescription;
dsTemp.Tables["Hotel_Details_Lang"].Rows.Add(drwChild);

daHotel_Details.Update(dsTemp);
daHotel_Details_Lang.Update(dsTemp);
}
catch (System.Exception EErr) {
throw new Exception(EErr.Message, EErr);
}
finally {
if (dsTemp != null) dsTemp.Dispose(); dsTemp = null;
}
}
Thanks in advance.

--
Fabio Negri Cicotti
Software Engineer
Nov 17 '05 #1
3 7488
> When I execute the code below I get the following message: "Cannot insert
the value NULL into column 'hdtID', table
'myinstance.mydb.Hotel_Details_Lang'; column does not allow nulls. INSERT
fails." Any idea?

The obvious explanation would be:
The column hdtID of the table Hotel_Details_Lang does not allow NULL
values.

Make sure it does have a value, like:
drwChild["hdtID"] = 1;

If the hdtID column is the primary key, it might be a good idea to make it
auto-increment. That way it will be filled with a unique number by
default.

Greetings,
Wessel
Nov 17 '05 #2
Sorry for my poor explanation.

As I said, the parent table has an identity primary key which is
automatically generated and I set on the child table the value for "hdtID"
using the dataset's method SetParentRow. Although when I create the dataset
I've defined the relation among them, it yet does not fetch the identity
value to pass to the child table. Any other idea?

The relation defined:

dsTemp.Relations.Add("Hotel_Details_X_Hotel_Detail s_Lang",
dsTemp.Tables["Hotel_Details"].Columns["hdtID"],
dsTemp.Tables["Hotel_Details_Lang"].Columns["hdtID"]);

dsTemp.Relations["Hotel_Details_X_Hotel_Details_Lang"].Nested = true;

Best regards.

Fabio Negri Cicotti
Software Engineer

"Wessel Troost" <no*****@like.the.sun> wrote in message
news:op.suifpk0bf3yrl7@asbel...
When I execute the code below I get the following message: "Cannot insert
the value NULL into column 'hdtID', table
'myinstance.mydb.Hotel_Details_Lang'; column does not allow nulls. INSERT
fails." Any idea?

The obvious explanation would be:
The column hdtID of the table Hotel_Details_Lang does not allow NULL
values.

Make sure it does have a value, like:
drwChild["hdtID"] = 1;

If the hdtID column is the primary key, it might be a good idea to make it
auto-increment. That way it will be filled with a unique number by
default.

Greetings,
Wessel

Nov 17 '05 #3
> I've defined the relation among them, it yet does not fetch the identity
value to pass to the child table. Any other idea?

Might have an idea: before you call Update() on the Hotel_Details DataSet,
the new row will not have an ID. So the framework couldn't give it an ID.

It would be logical if the ID would be passed on to the child row after
calling Update(), but it looks like that doesn't happen.

Does it help if you
- Call Update() on the parent row before adding the child row?
- Manually pass on the ID after calling Update() on the parent row?
(As in: drwChild["hdtID"] = drwParent["hdtID"];)

Just some ideas :)

Greetings,
Wessel
Nov 17 '05 #4

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

Similar topics

14
by: serge | last post by:
I have a scenario where two tables are in a One-to-Many relationship and I need to move the data from the Many table to the One table so that it becomes a One-to-One relationship. I need to...
10
by: Python_it | last post by:
Python 2.4 MySQL-python.exe-1.2.0.win32-py2.4.zip How can I insert a NULL value in a table (MySQL-database). I can't set a var to NULL? Or is there a other possibility? My var must be variable...
18
by: Pedro Pinto | last post by:
Hi there once more........ Instead of showing all the code my problem is simple. I've tried to create this function: char temp(char *string){ alterString(string); return string;
8
by: Martin Z | last post by:
INSERT INTO dbo.Transmission (TransmissionDate, TransmissionDirection, Filename, TransmittedData) VALUES (@TransmissionDate,@TransmissionDirection,@Filename,@TransmittedData); SELECT @retVal =...
0
ak1dnar
by: ak1dnar | last post by:
There is a Error getting while i am entering records using this jsp file. <%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %> <%@ include...
0
by: diane | last post by:
Just trying to upsize using VFP 9 with SQL 2005 using VFP remote views. One in particular keeps coming up and saying Cannot insert the value NULL into column, when I really don't think I am...
0
by: yukijocelyn | last post by:
I have experienced a problem here while doing a form for accessing datadbase using MS Access. I'm using the AccessDataSource control, and using Gridview to pull the data from the database. I am able...
6
by: pbd22 | last post by:
Hi. I am trying to insert a zero into the below table and I am being told that: Cannot insert the value NULL into column 'UsageToday', table DB.dbo.Pub_Count'; column does not allow nulls....
2
by: wizardry | last post by:
hello - i'm trying to insert a blob into my table, it will insert but the string that i insert when i query the inserted data returns null with 0 bytes in the column. I have other tables set...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.