473,698 Members | 2,084 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with OleDbTransactio n with Header and Itens tables

Hi,

I'm with the folowing problem:

I have two tables: header(id_heade r) and Itens(id_header , id_item).

When I insert data in Itens table, this error is returned: "You cannot add
or change a record because a related record is required in table 'header'."

I'm using MS Access database.

See the code:

OleDbConnection connection = new
OleDbConnection (DBConnection.G etConnectionStr ing());
OleDbTransactio n transaction = null;
OleDbCommand command = new OleDbCommand();

command.Connect ion = connection;

connection.Open ();

transaction = connection.Begi nTransaction();
command.Transac tion = transaction;

try
{
sql = "insert into header(id_heade r) values(@header) ";

OleDbParameter[] oleDbParameter = { new
OleDbParameter( "@header",id_he ader)};

command.Paramet ers.Clear();
for(int i=0; i<oleDbParamete r.Length; i++)
command.Paramet ers.Add(oleDbPa rameter[i]);

command.Command Text = sql;
command.Execute NonQuery();
sql = "insert into item(id_header, id_item)
values(@header, @item)";

OleDbParameter[] oleDbParameter = { new
OleDbParameter( "@header",id_he ader), new OleDbParameter( "@item",id_item )};

command.Paramet ers.Clear();
for(int i=0; i<oleDbParamete r.Length; i++)
command.Paramet ers.Add(oleDbPa rameter[i]);

command.Command Text = sql;
command.Execute NonQuery();

transaction.Com mit();
}
....

Thanks.
Dec 2 '05 #1
0 1085

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

Similar topics

2
3740
by: googley | last post by:
I'm starting a new thread for a problem that I ran into.. I'm trying to use STYLE SHEETS/CSS to update multiple table widths across many pages. I did get it working with one small problem that I can't figure out. For the sake of being really simple here are the steps i took. 1. create blank web page, create blank css page. 2. save 'em both, link them together.
1
1074
by: thomaz | last post by:
The Combobox SelectedIndex method doesn´t work in windows 98. If no one itens selected this method return ZERO (0) but the correct is (-1). According to the visual Studio help if not exist itens selected the method returns (-1) but always the method return (0). Zero is the index of the first item of a combobox. There is an error in a Combobox SelectedIndex in Windows 98??? Anybody can help me???
0
1178
by: Raphaël Désalbres | last post by:
Hello, everybody, I'm having a problem creating a control...All I want to do is a simple poll system, so I need to input (trough a ListitemCollection) the values from the user. The problem is I'm getting an error each time I try to modify the elements, I don't know why.... If anyone can help, I would appreciate...
4
1174
by: Raphaël Désalbres | last post by:
Hello, everybody, I'm having a problem creating a control...All I want to do is a simple poll system, so I need to input (trough a ListitemCollection) the values from the user. The problem is I'm getting an error each time I try to modify the elements, I don't know why.... If anyone can help, I would appreciate...
1
1413
by: Marco Roberto | last post by:
Hi, is there anyway to add itens into a combobox after this control be bound with a dataset? Regards, Marco
1
5124
by: John | last post by:
How can I include the following code in a transaction? How can I set the Transaction propertity for the call to MyDataAdapter.Update()? Thanks. ' Dim tr as OleDbtransaction = cnn.BeginTransaction Dim dr As DataRow = MyDataSet.Tables("Customer").NewRow dr(0) = "Smith" MyDataSet.Tables("Customer").Rows.Add(dr) MyDataAdapter.Update(MyDataSet,"Customer") 'tr.Commit
3
1673
by: no | last post by:
Hi all, I have a dataset that contain 2 tables and a relationship between them (master detail). I bind this dataset to a form that include some textboxes that bind to the parent record, and a datagrid that is binded to the detailed records. Here is the code: Code:
7
4822
by: Kamal | last post by:
Hello all, I have a very simple html table with collapsible rows and sorting capabilities. The collapsible row is hidden with css rule (display:none). When one clicks in the left of the expandable row, the hidden row is made visible with css. The problem is when i sort the rows, the hidden rows get sorted as well which i don't want and want to be moved (while sorting) relative to their parent rows. The following is my complete html code...
2
1984
by: arnabit | last post by:
Hi everyone, I am facing a problem in exporting CSV file.I able to export it properly in IE7 bbut in Mozila it seems the file name is changed and an extra , is added in the file name.say if the file name is "Report .csv" in mozila it becomes Report .csv," .I am writting the code below. private void ExportToCsv(DataSet ds) {
0
8672
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9156
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9021
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8892
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7712
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5860
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4361
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3038
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2323
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.