Hi, I am hoping I can get some help with a small problem I have run
into using C#. U have an XML file that I load into a Dataset and then
display this in a Datagrid. No problems doing this at all. I then use
a Dataview to filter this view using a keyword and I have no problems
with this either.
What I would like to do is to save this Dataview to a new Dataset so I
can save the reslts to a new file but here is where I am having the
problem. A Dataview is typically not written back to a Dataset so I'm
not sure what would be the best way to do this. I found a code snippet
after looking for a day but I have errors with it and I do not know
why.
I have created my main Dataset called 'ds' and after filtering it and
displaying it I clone 'ds' to a new Dataset and then try to import the
rows back into my new data set. The code I am using to do this is
posted below....
//*************** *************** *************** ******
DataSet ds2 = ds.Clone();
for(int iTable = 0; iTable < ds.Tables.Count ; iTable++)
{
for(int iRow = 0; iRow < ds.Tables[iTable].DefaultView.Co unt; Row++)
{
ds2.Tables[iTable].ImportRow(ds.T ables[iTable].DefaultView[iRow].Row);
}
}
ds2.WriteXml(@" c:\data.xml");
//*************** *************** *************** ****
My problem comes in on the this line...
for(int iRow = 0; iRow < ds.Tables[iTable].DefaultView.Co unt; iRow++)
The error that is displayed is as follows....
"An unhandled exception of type
'System.Data.In validConstraint Exception' occurred in system.data.dll
Additional information: ForeignKeyConst raint Computer_Comput erHardware
requires the child key values (3) to exist in the parent table."
On this part of the code three matches are found & displayed so I'm
not sure if it is important.
The error occurs on the 'iRow++' part pf the statement but I don't
know why. I can't set breakpoints in C# nor can I see where the error
is because I can't step through the code. Any idea of this would
happen? I'm really stumped on this, below is a snippet of my XML
document so you know what I am using in this code.
Thanks for any help, Dennis
//*************** *************** ***********
<Office_Invento ry>
<Computer>
<RoomNumber>G20 17</RoomNumber>
<ComputerNumber >G201701</ComputerNumber>
<InServiceDate> 2003-03-15</InServiceDate>
<ComputerHardwa re>
<Printer>HP DeskJet 500</Printer>
<Scanner>HP Scan 100</Scanner>
<CD-DVD>40X CD-ROM</CD-DVD>
<Monitor>Acer 67L</Monitor>
</ComputerHardwar e>
<ComputerSoftwa re>
<OS>Windows 2000</OS>
<Office>Offic e 2003 Professional</Office>
<Programming>Vi sual Studio 2003 Profressional</Programming>
<Utilities>Nort on AntiVirus 2005</Utilities>
</ComputerSoftwar e>
</Computer>
</Office_Inventor y> 2 5336
Hi,
The problem y ou have is with FKs apparently.
Another thing, a DataView a related to a DataTable, not to a DataSet.
So you DON'T want to clone the dataset, not even clone the table will works
always.
If you have a column that makes reference to anther table you may have a
problem.
You have to call DataTable.Clone and then iterate in the DataView.Rows to
copy them.
cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Dennis" <no**@none.co m> wrote in message
news:fk******** *************** *********@4ax.c om... Hi, I am hoping I can get some help with a small problem I have run into using C#. U have an XML file that I load into a Dataset and then display this in a Datagrid. No problems doing this at all. I then use a Dataview to filter this view using a keyword and I have no problems with this either.
What I would like to do is to save this Dataview to a new Dataset so I can save the reslts to a new file but here is where I am having the problem. A Dataview is typically not written back to a Dataset so I'm not sure what would be the best way to do this. I found a code snippet after looking for a day but I have errors with it and I do not know why.
I have created my main Dataset called 'ds' and after filtering it and displaying it I clone 'ds' to a new Dataset and then try to import the rows back into my new data set. The code I am using to do this is posted below....
//*************** *************** *************** ******
DataSet ds2 = ds.Clone();
for(int iTable = 0; iTable < ds.Tables.Count ; iTable++) { for(int iRow = 0; iRow < ds.Tables[iTable].DefaultView.Co unt; Row++) {
ds2.Tables[iTable].ImportRow(ds.T ables[iTable].DefaultView[iRow].Row); } } ds2.WriteXml(@" c:\data.xml"); //*************** *************** *************** ****
My problem comes in on the this line...
for(int iRow = 0; iRow < ds.Tables[iTable].DefaultView.Co unt; iRow++)
The error that is displayed is as follows....
"An unhandled exception of type 'System.Data.In validConstraint Exception' occurred in system.data.dll
Additional information: ForeignKeyConst raint Computer_Comput erHardware requires the child key values (3) to exist in the parent table."
On this part of the code three matches are found & displayed so I'm not sure if it is important.
The error occurs on the 'iRow++' part pf the statement but I don't know why. I can't set breakpoints in C# nor can I see where the error is because I can't step through the code. Any idea of this would happen? I'm really stumped on this, below is a snippet of my XML document so you know what I am using in this code.
Thanks for any help, Dennis
//*************** *************** *********** <Office_Invento ry> <Computer> <RoomNumber>G20 17</RoomNumber> <ComputerNumber >G201701</ComputerNumber> <InServiceDate> 2003-03-15</InServiceDate> <ComputerHardwa re> <Printer>HP DeskJet 500</Printer> <Scanner>HP Scan 100</Scanner> <CD-DVD>40X CD-ROM</CD-DVD> <Monitor>Acer 67L</Monitor> </ComputerHardwar e> <ComputerSoftwa re> <OS>Windows 2000</OS> <Office>Offic e 2003 Professional</Office> <Programming>Vi sual Studio 2003 Profressional</Programming> <Utilities>Nort on AntiVirus 2005</Utilities> </ComputerSoftwar e> </Computer> </Office_Inventor y>
There are a couple of things you can try. What's happening here is
that you are attempting to copy a constrained table into a data set
that does not have the external references. i.e. your table "parts"
has a column constraint that "parts.partSupp lier" must be a key in
"PartSuppli ers" By just iterating over the tables collection, you run
the risk of copying "parts" before "partssuppliers ," so you get the
constraints.
you might try setting the DataSet.Enforce Constraints propertyy false on
the target DataSet. If you then run the transfer, you might copy all
the tables over, but none of the constraints.
You might also need to explicitly export the relations, if you want
them, into the target DataSet. (See the DataSet.Relatio ns property).
Jim Katz
Senior Developer
Transform Pharmaceuticals jk***@transform pharma.com
Dennis wrote: Hi, I am hoping I can get some help with a small problem I have run into using C#. U have an XML file that I load into a Dataset and then display this in a Datagrid. No problems doing this at all. I then use a Dataview to filter this view using a keyword and I have no problems with this either.
What I would like to do is to save this Dataview to a new Dataset so I can save the reslts to a new file but here is where I am having the problem. A Dataview is typically not written back to a Dataset so I'm not sure what would be the best way to do this. I found a code snippet after looking for a day but I have errors with it and I do not know why.
I have created my main Dataset called 'ds' and after filtering it and displaying it I clone 'ds' to a new Dataset and then try to import the rows back into my new data set. The code I am using to do this is posted below....
//*************** *************** *************** ******
DataSet ds2 = ds.Clone();
for(int iTable = 0; iTable < ds.Tables.Count ; iTable++) { for(int iRow = 0; iRow < ds.Tables[iTable].DefaultView.Co unt; Row++) {
ds2.Tables[iTable].ImportRow(ds.T ables[iTable].DefaultView[iRow].Row); } } ds2.WriteXml(@" c:\data.xml"); //*************** *************** *************** ****
My problem comes in on the this line...
for(int iRow = 0; iRow < ds.Tables[iTable].DefaultView.Co unt; iRow++)
The error that is displayed is as follows....
"An unhandled exception of type 'System.Data.In validConstraint Exception' occurred in system.data.dll
Additional information: ForeignKeyConst raint Computer_Comput erHardware requires the child key values (3) to exist in the parent table."
On this part of the code three matches are found & displayed so I'm not sure if it is important.
The error occurs on the 'iRow++' part pf the statement but I don't know why. I can't set breakpoints in C# nor can I see where the error is because I can't step through the code. Any idea of this would happen? I'm really stumped on this, below is a snippet of my XML document so you know what I am using in this code.
Thanks for any help, Dennis
//*************** *************** *********** <Office_Invento ry> <Computer> <RoomNumber>G20 17</RoomNumber> <ComputerNumber >G201701</ComputerNumber> <InServiceDate> 2003-03-15</InServiceDate> <ComputerHardwa re> <Printer>HP DeskJet 500</Printer> <Scanner>HP Scan 100</Scanner> <CD-DVD>40X CD-ROM</CD-DVD> <Monitor>Acer 67L</Monitor> </ComputerHardwar e> <ComputerSoftwa re> <OS>Windows 2000</OS> <Office>Offic e 2003 Professional</Office> <Programming>Vi sual Studio 2003 Profressional</Programming> <Utilities>Nort on AntiVirus 2005</Utilities> </ComputerSoftwar e> </Computer> </Office_Inventor y> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Arthur Dzhelali |
last post by:
I according to MSDN dataview and dataset are thread safe for read
operations, but we run into this scenario. I just would like to see some
comments on it.
Aplication written in VB.NET it is an ASP.NET app.
located on busy web server.
Initially we defined dataview slightly wrong and run into the problem.
we have dataset cached which has large ammount of data.
|
by: Nikhil Patel |
last post by:
Hi,
I bind a grid to a DataView object. I lose the reference to the underlying
DataTable and the DataSet in a postback.
Here is the code. Page_Load works fine and I am able to see the rows in grid
and edit them. But I don't know how to save the data back to the database
when the user clicks on a Button. Thanks.
private void Page_Load(object sender, System.EventArgs e)
{
|
by: Jay Zweedyk |
last post by:
Ok I want to filter a dataset into a dataview and be able to reference back
to the dataset from the filtered dataview.
Example:
100 record dataset
filter it to a 5 record dataview
loop thought the Dataview and update the original dataset .... if there is a
way to index the dataset from the dataview. I know I can update the
|
by: kjvt |
last post by:
Based on a prior posting, I've written a function to convert a
recordset to a dataview. The first call to the function for a given
recordset works perfectly, but the second call always returns a
dataview with a count = 0. Can someone explain why and how I might
work around this problem?
Here is the code for my function:
Public Shared Function GetViewFromRS(ByVal pRS As ADODB.Recordset) _
As DataView
|
by: Steve |
last post by:
I have a form with a dataset and a datagrid.
I created a dataview on this dataset.
When the user modifies the datagrid, I look up this record in the dataview
to make sure it is unique.
Here is the confusion.........
I thought that the DataView is the view from the dataset, but it seems that
the dataview has the records that are in the datagrid, because everytime I
search for a record that I know is NOT in the dataset, it finds it. I...
| |
by: David Wender |
last post by:
I want to create a dataview with a sort on multiple columns. However,
when I use FindRows, I only want to search some of the columns, not
all. Is this possible? I have not been able to make it happen.
Dim objKeys(2) as Object
objKeys(0) = "CL"
objKeys(2) = 4000
Dim posView As DataView = New DataView(posDS.Tables("Positions"), _
|
by: Bob Davies |
last post by:
Hi
I have a webservice that retrieves data from a database, this is then
returned to the calling client application built in windows forms within a
dataset, however upon attempting to create tablestyles to format any of the
columns within the datagrid, the exception "Can-not parent objects created
on one thread to objects created on another" or words to that effect.
I'm not too sure if what I said make sense, but i will add details to...
|
by: A_PK |
last post by:
I have problem databinding the DataGrid with DataView/DataSet after the
filter...
I create the following proceudre in order for user to filter as many as they
want, but the following code is only allow user to filter the first time,
when they tried the second time, the speficied cast error message will
prompt one....
I create a mydataset1 first, and the mydataset1 data source was getting from
DataGrid.DataSource.
|
by: James |
last post by:
Basically I have a DataGrid that I'm binding to the results of a stored
procedure call. The recordset is fairly small. Initially I'm creating a
DataSet from the results and binding it. There's a DropDownList on my page
that filters the records that are displayed in the grid.
How I'm currently handling this is when I initially bind, I create a
DataView from the table in the dataset. When the DropDownList changes
selection, I get the...
|
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...
|
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...
| |
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,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |