473,748 Members | 7,142 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I add a row from a typed datatable to another instance of that typed datatable?

I have 2 typed data tables inherited from the same dataset schema
One called : table A with an identity column x
column x is constrained to be unique.
Other one is : table B with an identity column x

There are some rows in table A and table B.
When I want to add a row from table A to table B I use the function

TableA.ImportRo w(TableB.rows[1]); // for example

If the column x values are the same I get the error :

Column 'column x' is constrained to be unique. Value '34' is already
present.

I want TableA to continue increasing values from the greatest value in Table
B

I tried making column A's values to null but it didn't worked.

TableA.SetColum nXNull();

How can I add a row from a typed datatable to another instance of that typed
datatable with an auto incremeant and uniqe column.

thanks ,
ersin


Nov 18 '05 #1
1 2265
Uzytkownik "Ersin Gençtürk" <ers[spam]@gencturk.org> napisal w wiadomosci
news:uF******** ********@TK2MSF TNGP12.phx.gbl. ..
I have 2 typed data tables inherited from the same dataset schema
One called : table A with an identity column x
column x is constrained to be unique.
Other one is : table B with an identity column x

There are some rows in table A and table B.
When I want to add a row from table A to table B I use the function

TableA.ImportRo w(TableB.rows[1]); // for example

If the column x values are the same I get the error :

Column 'column x' is constrained to be unique. Value '34' is already
present.

I want TableA to continue increasing values from the greatest value in
Table
I'm not sure if there is any simple method to do it. I propose that
solution:

public void AddR()
{
foreach(DataRow dr in tableA.Rows)
ImportOneRow(ta bleB, dr);
}
private void ImportOneRow(Da taTable targetTable, DataRow sourceRow)
{
//"Id" - name of identity column
int curId = (int)sourceRow["Id"];
//temporary changing value of identity column
sourceRow["Id"] = -1;

//importing new row
targetTable.Imp ortRow(sourceRo w);

//restoring previous value of identity column
sourceRow["Id"] = curId;

//computing current value of identity column
object ob = targetTable.Com pute("Max(Id)", "Id <> -1");
int id;
if(Convert.IsDB Null(ob))
id = 1;
else
id = (int)ob + 1;

//assigning proper value of identity column in target table
DataRow drTarg = targetTable.Row s.Find(-1);
drTarg["Id"] = id;
}

I hope that it helps.

Regards,
Grzegorz

"Ersin Gençtürk" <ers[spam]@gencturk.org> wrote in message
news:eE******** ******@TK2MSFTN GP15.phx.gbl... I have 2 typed data tables inherited from the same dataset schema
One called : table A with an identity column x
column x is constrained to be unique.
Other one is : table B with an identity column x

There are some rows in table A and table B.
When I want to add a row from table A to table B I use the function

TableA.ImportRo w(TableB.rows[1]); // for example

If the column x values are the same I get the error :

Column 'column x' is constrained to be unique. Value '34' is already
present.

I want TableA to continue increasing values from the greatest value in Table B

I tried making column A's values to null but it didn't worked.

TableA.SetColum nXNull();

How can I add a row from a typed datatable to another instance of that typed datatable with an auto incremeant and uniqe column.

thanks ,
ersin


Nov 18 '05 #2

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

Similar topics

2
2888
by: theWizK | last post by:
Hello all. I have noticed that when I generate a strongly-typed dataset from an xml schema that the DataTables that are generated have their constructors marked as internal. What this means is when I try to instantiate one of the strongly-typed tables from this dataset from a different assembly, I cannot. Let me provide examples... If I have a simple dataset like this:
1
6822
by: Somebody_Out_There | last post by:
Hello, I am trying to create a strongly typed datatable/dataset from an untyped dataset or datatable returned from a stored proc. The structure of the table cannot be static since the results are dynamic which means that I am right now creating the schema/structure of the datatable from a datareader using reader.GetSchemaTable() and then looping thru the reader to populate values. Is there any other efficient way of achieving this?...
3
6491
by: Rakesh Rajan | last post by:
Hi, I have a method, which opens a connection, creates an untyped datable, fills it and returns it back. I have defined a typed datatable in my application as well. For some reasons, I have to call the above mentioned method to get data. Unfortunately, as it returns an untyped datatable, I can't assign my typed datatable variable this value (a base type can't be converted into a sub type automatically). Without resorting to looping thru...
2
2060
by: Mark | last post by:
Assume you have a strongly typed collection of a class called Person. The strongly typed collection implements IEnumerable so it can be databound to a server control like a DataGrid. The Person class has several public properties like FirstName, LastName, and Gender. What steps would it take to allow the collection to be sorted in multiple ways when bound to a DataGrid? In the past, I used the sort property of a DataView containing a...
0
1118
by: Magnus | last post by:
I would like to filter data in a typed datatable, while maintaining strong type references. The typed dataset/datatable is generated using vs2005 xsd.exe tool from a xml schema definition file. I don't understand how this is possible when its the dataview that is being used to filter. To filter I have to get the "defaultview" from the datatable, and the
3
4875
by: Jon B | last post by:
Hi There! I'm looking into Strongly Typed DataSets in the .NET Framework. I know it can generated strongly typed tables as objects and column names as properties. However, one thing that I would like to know is if it wraps database Stored Procedures as methods and functions? For instance, if I have a Stored Procedure called SelectBestProduct in the Product table, would I be able to call the Stored Procedure with
0
1058
by: timnels | last post by:
I have a strongly-typed DataTable I need to save as XML and later reload it. I thought that all I had to do was: menuDataTable.WriteXml(filename,XmlWriteMode.WriteSchema); And from another application do: menuDataTable.ReadXml(filename);
21
2430
by: Peter Bradley | last post by:
Hi all, This post is sort of tangentially related to my earlier posts on configuration files for DLLs. Does anyone know how to create typed DataSets using VS2005's new DataSet designer, but with the ability to configure the connection string via a config file? The designer seems to hard-code the connection string into the dataset itself, which just can't be right.
1
3570
by: Code Monkey | last post by:
Silly question maybe, but I've been doing the following for far too long now: public static DataTable myDataTable() { string sql = @"SELECT column1, column2, column3, column4 FROM myTable"; using (SqlConnection conn = new SqlConnection(websqlconn)) { SqlCommand cmd = new SqlCommand(sql, conn);
0
8991
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
8830
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9370
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...
0
9247
tracyyun
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...
0
8242
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...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6074
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();...
1
3312
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
2782
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.