How to merge 2 tables fields in DataTable in asp.net
Answers were Sorted based on User's Feedback
you can use the query to merge the fields.that query will
be executed through the sqlcommand.
| Is This Answer Correct ? | 22 Yes | 8 No |
Answer / ankur sehgal
Consider a dataset(ds) having two datatables or we can say
that it contains data from two tables..
System.Data.DataTable dt = new DataTable();
dt.Columns.Add("Field1", typeof(string));
dt.Columns.Add("Field2", typeof(string));
if(ds.Tables[0].Rows.Count > 0)
{
foreach(DataRow dr in ds.Tables[0].Rows)
{
DrNew = dt.NewRow();
DrNew[0] = dr["Field1"].ToString();
}
}
if(ds.Tables[1].Rows.Count > 0)
{
foreach(DataRow dr in ds.Tables[1].Rows)
{
DrNew = dt.NewRow();
DrNew[0] = dr["Field2"].ToString();
}
}
dt.AcceptChanges();
| Is This Answer Correct ? | 22 Yes | 15 No |
Answer / sunil kumar
DataTable dt1 = retDT("select col1,col2 from Table1");
DataTable dt2 = retDT("select col3,col4 from Table2");
dt1.Merge(dt2);
retDT is a funtion to return datatable based on the query.
The output will be like below
if you check the dt1 content then the output will be
col1 col2 col3 col4
1 2 3 4
| Is This Answer Correct ? | 21 Yes | 15 No |
You Can Write Query :
select (databasename).(owner).(tablename1).
(datafield),select (databasename).(owner).(tablename2).
(datafield) from (databasename).(owner).(tablename1),
(databasename).(owner).(tablename2)
Example:select
LSKGROUP.dbo.addsites.state,LSKGROUP.dbo.employee.empname
from LSKGROUP.dbo.addsites,LSKGROUP.dbo.employee
and then fill the values to new dataset table.
Remember:
if database also differ put databse's name accordingly
Good Luck.....
| Is This Answer Correct ? | 13 Yes | 8 No |
Answer / abc
DataTable dt1 = retDT("select col1,col2 from Table1");
DataTable dt2 = retDT("select col3,col4 from Table2");
dt1.Merge(dt2);
retDT is a funtion to return datatable based on the query.
The output will be like below
if you check the dt1 content then the output will be
| Is This Answer Correct ? | 3 Yes | 0 No |
Answer / k
get data from first table and add it as a column in another
table and do the same way to retrive the second data from
other table.Add it to third column..
| Is This Answer Correct ? | 9 Yes | 11 No |
What is the main difference between a static page and a dynamic page?
What is the relationship(in oops) between codebehind and inline code(.aspx to .aspx.cs)??? explain
What is asp short for?
We are using Jscriopt validations and at clint site javascript is not running that time validation would work? if yes then how it would behave?
a)COM Callable Wrapper b)Runtime Callable Which one of the above is Win32 API in .Net?
What tags do you need to add within the asp:datagrid tags to bind columns manually? How?
What is asp.net web application?
Where on the Internet would you look for Web services?
5 Answers IBM, MNC, Siebel Systems,
What are web beacons used for?
Is asp.net free?
Do I need to have the latest version of windows media player installed?
What is Model-View-View Model?
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)