Solved

datatable in asp.net - merge

Posted on 2011-03-07
4
459 Views
Last Modified: 2012-05-11
Is there a way to merge year, make and model columns to one column, year_make_model?


datatable_1

orderdate      year      make      model
03/07/2011      2003       honda      civic exc

after

orderdate       Year_make_model
0
Comment
Question by:VBdotnet2005
  • 2
4 Comments
 
LVL 3

Expert Comment

by:chrisrbloom
ID: 35062249
Dim stYear, stMake, stModel, stCombined as String

stYear = {get year from datatable}
stMake = {get make from datatable}
stModel = {get model from datatable}

stCombined = stYear + " " + stMake + " " + stModel
0
 
LVL 13

Expert Comment

by:gamarrojgq
ID: 35062265
HI,

Did you application allows you to do it from the data source?  I mean from your query, something like this (assuming you are using SQL Server)

Select OrderDate, Convert(varchar, Year) + '_' + Make + '_' + Model As Year_Make_Model
From yourtable

or you have to do it once the data is in memory?
0
 

Author Comment

by:VBdotnet2005
ID: 35063921
Once the data in memory
0
 
LVL 13

Accepted Solution

by:
gamarrojgq earned 500 total points
ID: 35064276
Hi,

After you populate you Datatable_1, you can add a Calculated column like this

datatable_1.Columns.Add("Year_Make_Model", GetType(System.String), "Year + ',' + Make + ',' + Model")

And after that you can read the value from the new merge column

        MsgBox(datatable_1.Rows(0)("Year_Make_Model"))
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

832 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