.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

C#: How to add a row to a child table with a DataSet backing?

Posted By:      Posted Date: August 31, 2010    Points: 0   Category :.NET Framework
On the back end I am using XML files, xsd schemas a DataSet(dsThingPrograms) and DataTables. I have a parent ->child table relationship defined through the DataSet designer as such:   things[RFID(pkey), name] programs[ID(pkey/autogen), name, path, thing_RFID(FK references things->RFID)]   In my code I have:   dsThingPrograms.things.AddthingsRow("lala" , "00ffe4" ); dsThingPrograms.things.WriteXml("path\to\things.xml" , System.Data.XmlWriteMode.WriteSchema);   which works fine. However the problem comes when I try to add a row to the Programs table. When I do:   dsThingPrograms.programs.AddprogramsRow("someprog" , "some\path" , <???>);   VS wants me to add a "dsThingPrograms.thingsRow parentthingsRowByFK_things_programs" where the <???> is. I've tried a bunch of things but I could not satisfy that requirement and can't even get the code to compile. What is supposed to go in there to satisfy the FK property?

View Complete Post

More Related Resource Links

Display column from child table. Possible ?



I'am using dnamic entity with EF4. On a list page of a table, I would like to display a column containing information from a child table of the current element. Sample :

Order List :

Order Data | Required Date | Shipped Date | etc... | ... | Customer Name (foreign key with tostring() method override) | Customer Postal Code (Column that I want to add) |

I don't known how to do that. Is it possible ? Maybe I have to to create my own Metadata proxy that will add dynamicly a column on the MetaColumn list of the table.

Does someone have an easier or better idea ?

Thank you for any help.

merging multiple tables in a single dataset to single table


 i have a stored procedure which returns three tables to a dataset ..... now i need to merge all three tables to a single table from d same dataset 

like dataset1 has table1 table2 and table3 .... i want all the three tabels to be merged into dataset1 itself .... instead of three diffrent tables so that i can show all three table data in a single datagrid  as a compact data and combination of 3 tables from d single dataset.....

can some1 help me please.....

InfoPath and Access - two parent tables and one child table


Hi there,

I'm trying to link an InfoPath form to an Access database, I want to connect the InfoPath form to 3 tables in the Access database but InfoPath will only recognise parent-child relationships in a series (e.g. the "Company" table is the parent to the "Customer" table, which is again parent to the "Orders" table)

I need to have two parent tables and one child table, though (e.g. "Customer" is parent to "Orders", but "Inventory_Item" is also parent to "Orders"). Is there any way to establish this in InfoPath? I'm using Windows XP, InfoPath 2007 and Access 2007.

Cheers, Patrick

SQLCE table column DefaultValues don't show up in XSD Dataset designer

Using Visual Studio 2008 with SQL CE 3.5, I notice that default values in the creation scripts for the database tables are not reflected in the dataset designer XSD file.  For example, the following SQL script creates the non-nullable table column names "Content" with a default value of 'Image':    "Content" nchar(20) NOT NULL DEFAULT 'Image',But in the column properties of the dataset designer (XSD) panel, this column correctly shows up as non-nullable, but with a DBnull default value as follows:     Name: Content    Allow DBnull: False    DefaultValue: <DBnull>Am I missing something somewhere, or is this a VS bug?  Also, how do I get the XSD file to regenerate after schema changes in the database?  Sqlmetal doesn't do it.Thanks,    -BGood

setting schema as dataset to a table

hiii have an already existing schema (in a xsd file). now i need to prepare a report, so in the rdlc page i take a table. now how can i set the schema as a dataset to the table?(i'm getting an error -- "the table 'table1' is in the report body but the report has no data set.  Data regions are not allowed in reports without datasets.").  

Arrange columns from nested table in a dataset that writes into XML file



I have 3 related data tables. I added these tables into a dataset and finally write it to a XML file. But the related columns from table 2 and 3 is appended after all the columns from table 1. How can I have something like:
in a dataset that I write to XML instead of

dataset table adapter commands



how i can disable generation of insert update delete select commands in tableadapter or how i can

remove all of these commands in dataset?


tank u in advance

Update a table from a dataset



I have a data flow task in which I have a dataset containing some rows and now I want to update the rows in a table, not insert them. Is there any way to do that in the task?



How to get Default value in table to work when NULL in DataSet

Is this possible? If the parameter value is NULL in DataSet, the default value is not assigned.

Multiple Dataset in one table


Hi All,

I have one table with three column say


where A is Metrics column ,B having sum (Metrics) of one day ,C having sum(metrics) of 2 days as below


Metrics                          1 day                                             2 day

A                      12 (Value of Column B)           67 (Value of Column C)



B and C will come from different dataset,kindly sugest how to do this,i have to retreive data on the basis of Metrics.



Insert data in parent and child table at the same time


I have two (parent-child) tables that are bound by a primary key (PK)/foreign key (FK) relation.each PK is identity (idStudent and idBac)

to insert data, i'm using an little application in c# i programmed myself where i insert these columns for the Student table: F_Name, L_Name, Age, Mobile, Adresse, City ,and  ( i don't know how to handle the idBac wich is foreign key of the other table wich still not inserted yet)

for the table Bac, i insert section, school, and city.

what i want is when i click on "OK" button, the idBac ,wich is a foreign key of the other table (BAC), receives the same idBac given the moment i inserted the BAC informations too ...

i don't have any problem wich ado.net ...i just want the right query/procedure.

thanks in advance and sorry for my english, it's not my mother tongue.

DataSet Table Names


Hello, this is probably a stupid question, but is there anyway to pass in a Table Name to a DataSet?

I'm executing a stored procedure that is returning several recordsets. I have no problems w/ changing the DataTable's name from my Code Behind, but I was wondering if there was anyway the stored procedure could actually pass back the name of each recordset/datatable?

I hope this made sense! :) 

Binding a Dataset with Parent - Child



I have been tearing my hair out with this one.


I have a DataSet with two tables "Services" and "Methods" connected by a relation "FK_Service_Method.

I have populated a TreeView using the HierarchicalDataTemplate and that works fine.

Now I have two TextBoxes, one bound to ServiceName the other MethodName.

If I click on the ServiceName in the TreeView the bound ServiceName Textbox updates and the MethodName TextBox gets the first child MethodName

BUT if I click on a child MethodName I can't get the MethodName TextBox to reflect my change.

Here is the XAML



        <CollectionViewSource x:Key="ServicesDataView" Source="{Binding Path=Service}

Creating Table from DataSet


Hello all,

Real simple one here.  I'd like to create a table on my Page from a DataSet.  It looks like I have it working properly, but what I'd like to do is interpret the columns, as well as be selective with which column to display.

            Dim dc As DataColumn
            Dim dr As DataRow

            For Each dr In ds.Tables(0).Rows

                Dim trow As New TableRow

                For Each dc In ds.Tables(0).Columns

                    Dim tcell As New TableCell

                    tcell.Controls.Add(New LiteralControl(dr(dc.ColumnName).ToString))



I would like specific columns, by name or position doesnt matter.

So if a column is = named column, then addcell

and also, the data needs to be interpreted: If value of column = x then response.write("y")

In sum, I dont want all the columns, just specific ones, then I was to interpret whats in that cell, and write something.

For Each dc In ds.Tables(0).Columns

first ssis project - with master child table


Hello all,

I'm planning to develop a new SSIS project where I have a data in a table (Raw form) and I want to put into our production database. I just want to start with a test project and if you provide me little inside that will be helpful.

Here is what I'm trying to do

Typical order table (Order Header and Order Detail)

Temporary table with raw data which need to import in Order Table.

Order Header contains auto increment primary key which needs to be in order details table. So how should I develop a project where I go thru each record of temp table, write a record in order table, get order id (pk) and write data in order detail table.

Hope it is very much clear.

Hopefully I will get expert advice soon.

Thanks in advance,



mark it as answer if it answered your question :)

How to add cells to html table from dataset


I'm trying to code an html table dynamically, adding the data from a dataset - -

(by the way, the output is on a mobile device)

I keep getting an error:
Multiple controls with the same ID 'tcell0' were found. FindControl requires that controls have unique IDs.

Here's the code (including what I've tried - commented out):

  Dim i As Integer

  ' For Each dc In ds.Tables(0).Columns

  For i = 0 To ds.Tables(0).Columns.Count - 1

  Dim tcell As New HtmlTableCell

  tcell.ID = "tcell" & i.ToString

  tcell.InnerText = dr(i).ToString() & "-" & tcell.ID  

  'tcell.ID = "tcell" & i.ToString


  'i += 1



if I don't add the cell.id, all the text gets added to t

Create a XML file from Database table using Dataset



I've got a SQL database with a table named contact with different column such Name, Address, email ...

I would like to generate a XML file based on the table data:


     <name> John</name>

    <address> 100 main street </address>



After some research it looks like I can use a dataset from that table to create my xml.

Being a beginner I cannot find the right steps / syntax to do so.

Is there any tutorial showing how to work with dataset and XLM?

Thank you for your helps 


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend