473,569 Members | 2,617 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.myd b.Hotel_Details _Lang'; column does not allow nulls. INSERT
fails." Any idea?

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

public void Insert_Hotel_De tails(string hdtDescription) {
DataSet dsTemp = null;
try {
// Get the dataset with those two tables to use;
dsTemp = Get_Hotel_Detai ls();

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

//Child Table;
DataRow drwChild = dsTemp.Tables["Hotel_Details_ Lang"].NewRow();
drwChild.SetPar entRow(drwParen t);
drwChild["lngID"] = 1;
drwChild["hdtDescription "] = hdtDescription;
dsTemp.Tables["Hotel_Details_ Lang"].Rows.Add(drwCh ild);

daHotel_Details .Update(dsTemp) ;
daHotel_Details _Lang.Update(ds Temp);
}
catch (System.Excepti on 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 7501
> When I execute the code below I get the following message: "Cannot insert
the value NULL into column 'hdtID', table
'myinstance.myd b.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_L ang 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.Relation s.Add("Hotel_De tails_X_Hotel_D etails_Lang",
dsTemp.Tables["Hotel_Deta ils"].Columns["hdtID"],
dsTemp.Tables["Hotel_Details_ Lang"].Columns["hdtID"]);

dsTemp.Relation s["Hotel_Details_ X_Hotel_Details _Lang"].Nested = true;

Best regards.

Fabio Negri Cicotti
Software Engineer

"Wessel Troost" <no*****@like.t he.sun> wrote in message
news:op.suifpk0 bf3yrl7@asbel.. .
When I execute the code below I get the following message: "Cannot insert
the value NULL into column 'hdtID', table
'myinstance.myd b.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_L ang 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
4276
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 salvage the records from the many table and without going into detail, one of the reasons I can't do the opposite as there are records in the ONE table...
10
52490
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 string or NULL. Becaus i have a if statement: if .... cursor.execute(".................insert NULL ..............") if ....
18
4029
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
13927
by: Martin Z | last post by:
INSERT INTO dbo.Transmission (TransmissionDate, TransmissionDirection, Filename, TransmittedData) VALUES (@TransmissionDate,@TransmissionDirection,@Filename,@TransmittedData); SELECT @retVal = SCOPE_IDENTITY(); Pretty simple. There is an additional TransmissionID column that is an autonumber and primary key. @retVal is always null in my...
0
2140
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 file="../Connections/conn.jsp" %> <% // *** Edit Operations: declare variables // set the form action variable String MM_editAction =...
0
2072
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 inserting a NULL value. Oddly sometimes it works but I don't know why. Can anyone suggest anything else I can try? Perhaps this is the wrong group I'm...
0
1790
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 to see the contents in the database, but whenever I click "Delete" or "Update", the data never gets deleted or get updated repectively. It feels as if...
6
1821
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. UPDATE fails. The statement has been terminated. What I am trying to insert is a string that I convert into an int
2
5022
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 up this way and i'm able to insert text data into it with no problems. I've checked the database design its basiclly a duplicate. I did have to remove...
0
7701
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7615
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8130
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1223
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
940
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.