i have two datable with dissimilar column and i want to merge into one table .in c# window appli

Posted by Premjit06 under C# on 1/6/2012 | Points: 10 | Views : 1408 | Status : [Member] | Replies : 3
i have two datable with dissimilar column and i want to merge into one table .in c# window application .. my table look like this .

Table 1:

Slno Type Variable Data type size
1 0 A 1 1X1X1
2 0 B 1 1x1x1
3 0 C 6 3x2x1

Table2:
Value .
11
12
13
14
15
16
17
18

Table 3:
Slno Type Variable Value Data type size
1 0 A 11 1 1X1X1
2 0 B 12 1 1x1x1
3 0 C 12 6 3x2x1
C 13
C 14
C 15
C 16
C 17
C 18

thanks in Adv . i want this one very urgent.pls.

thanks
premjit




Responses

Posted by: Ogipansrk on: 1/6/2012 [Member] Starter | Points: 25

Up
0
Down
Hi premjit,
You can use Merge Option.
ForExample :

DataTable dt1 = new DataTable();
dt1.Columns.Add("Slno", typeof(string));
dt1.Columns.Add("Type", typeof(string));
dt1.Columns.Add("Variable", typeof(string));
dt1.Columns.Add("Type1", typeof(string));
dt1.Columns.Add("Size", typeof(string));

dt1.Rows.Add("1", "onetype", "aa", "aaa", "aqswwq");

DataTable dt2 = new DataTable();
dt2.Columns.Add("value", typeof(int));
dt2.Rows.Add("100");

DataTable dt3 = new DataTable();
dt3.Merge(dt1);
dt3.Merge(dt2);

Hope diz helps




Premjit06, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Premjit06 on: 1/9/2012 [Member] Starter | Points: 25

Up
0
Down
hi thanks , but i want the 3rd table look like this .
Slno Type Variable Value Datatype
1 0 A 1 1X1X1
2 0 B 11 3X2X1
3 0 B 12 3X2X1
3 0 B 13 3X2X1
3 0 B 14 3X2X1
3 0 B 15 3X2X1
3 0 B 16 3X2X1
the "Value" to be should be added in new 3rd table .



Premjit06, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ogipansrk on: 1/9/2012 [Member] Starter | Points: 25

Up
0
Down
Hi premjit,

U can use, the property TableName.Columns["ColumnName"].SetOrdinal(int)
example:
------------
dt3.Columns["Slno"].SetOrdinal(0);
dt3.Columns["Type"].SetOrdinal(1);
dt3.Columns["Variable"].SetOrdinal(3);
dt3.Columns["value"].SetOrdinal(4);
dt3.Columns["DataType"].SetOrdinal(5);

This will solve your problem



Premjit06, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response