[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

create two datatable from single datatable

Posted on 2006-11-15
10
Medium Priority
?
332 Views
Last Modified: 2010-04-16
Hi,
 I have a dataset datatable
select ORDER ,
         DESCRIPTION,
      FIRSTNAME,
     LASTNAME,
      ADDRESS,
      ZIP
     FROM Order

I need to select only Order and description and insert in to the another datatable
then select other firstname,lastname,address,zip to another datatable and assign this two datatable to new dataset
how to do that?
regards.
Nanban
0
Comment
Question by:nanban
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 13

Expert Comment

by:newyuppie
ID: 17953816
you would have to create a dataview, then you can create datatables from there:

DataView dv = new DataView(datatable);

DataTable newTable1 = dv.ToTable("OrderDesc",
             false, new string[] { "ORDER", "DESCRIPTION" });
DataTable newTable2 = dv.ToTable("Rest",
             false, new string[] { "FIRSTNAME", "LASTNAME", "ADDRESS", "ZIP" });

now you need to create a dataset and add these two new tables.
DataSet dataset1 = new DataSet("MyNewDataset");
dataset1.Tables.Add(newTable1);
dataset1.Tables.Add(newTable2);

0
 

Author Comment

by:nanban
ID: 17953880
What is totable?
I thought only using datarow we can get the required column and send in to table.
0
 
LVL 13

Accepted Solution

by:
newyuppie earned 150 total points
ID: 17953892
totable is a method of dataview that extracts the info to a datatable. look at the MSDN docs to find out how it works.
nice thing about ToTable is that it extract only certain columns as you can see from what i posted. it avoids loops that you may need to write otherwise
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:nanban
ID: 17954479
If i want to add autoincrement column with the table how to do that?
0
 
LVL 13

Expert Comment

by:newyuppie
ID: 17955284
to add an autoincrement column to a datatable you would do something like:


DataColumn workColumn = newTable2.Columns.Add("CustomerID", typeof(Int32));
workColumn.AutoIncrement = true;
workColumn.AutoIncrementSeed = 1;
workColumn.AutoIncrementStep = 1;
0
 

Author Comment

by:nanban
ID: 17963697
When we are using autoincrement column after totable the previous column dont have any value so how to add the b4 totable. if are adding autoincrement column b4 totable then calling totable delete the autoincrement column. what to do for that?
0
 
LVL 13

Expert Comment

by:newyuppie
ID: 17963950
with the technique i posted add the autoincrement replacing newTable2 with the name of your original datatable. then proceed with the totable technique and because the way we constructed it it will drop the autocolumn and the new tables wont have it.
0
 

Author Comment

by:nanban
ID: 17964024
Actually what is the problem is I need to create two auto increament column one is orderid and another one is contackkey and i need to releate the newly created table with primarykey foreignkey relationship so newly created order table has four coulmns contatkey,orderid,ORDER,DESCRIPTION first i need to insert contact table and then with the autogenerated column contackkey i need to insert in to order table with relationship

Shall i create the new thread or proceed with this thread... coz already we closed the thread :-) ?
Regards
Nanban.
0
 
LVL 13

Expert Comment

by:newyuppie
ID: 17964052
i believe the proper way to do it would be to create a new thread, in any case to get help from other experts as well. just put your new question and a link to this one if people want to see where you stand.
0
 

Author Comment

by:nanban
ID: 17970104
Hi
I have created a new thread for this...
http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_22065240.html

thanks a lot.....

Regards,
Nanban.
0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question