473,499 Members | 1,539 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.ImportRow(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.SetColumnXNull();

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 2242
Uzytkownik "Ersin Gençtürk" <ers[spam]@gencturk.org> napisal w wiadomosci
news:uF****************@TK2MSFTNGP12.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.ImportRow(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(tableB, dr);
}
private void ImportOneRow(DataTable 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.ImportRow(sourceRow);

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

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

//assigning proper value of identity column in target table
DataRow drTarg = targetTable.Rows.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**************@TK2MSFTNGP15.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.ImportRow(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.SetColumnXNull();

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
2846
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...
1
6797
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...
3
6469
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...
2
2043
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...
0
1111
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....
3
4857
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...
0
1045
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...
21
2389
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...
1
3531
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...
0
7171
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,...
1
6893
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...
0
7386
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...
0
5468
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,...
1
4918
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...
0
4599
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...
0
3098
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...
0
1427
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 ...
1
664
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.