Solved

Combine two columns

Posted on 2016-09-29
3
42 Views
Last Modified: 2016-09-30
Hi,

I am getting a dataset from a query, I would like to combine two fields into one. This is my code, but I am getting error. any ideas?  thanks

        DataSet ds = new DataSet();
        da.Fill(ds);

        listBox1.DataTextField = ds.Tables[0].Columns["Name1"].ToString();
        
        ds.Tables[0].Columns.Add("CombineName", typeof(string), "Name1 + '*' + Name2");
        listBox1.DataValueField = ds.Tables[0].Columns["name"].ToString();



        listBox1.DataSource = ds.Tables[0];
        listBox1.DataBind();

Open in new window

0
Comment
Question by:mcrmg
3 Comments
 
LVL 12

Accepted Solution

by:
Ramkisan Jagtap earned 500 total points
ID: 41822960
you can combine them in your query and get it in the results as below so that you dont need to add it in the code like below:

select concat(Name1,'* ', Name2) as CombineName
from yourTable

so just add "concat(Name1,'* ', Name2) as CombineName" in your query
1
 
LVL 23

Expert Comment

by:Ioannis Paraskevopoulos
ID: 41822982
What kind of error do you get?
0
 

Author Closing Comment

by:mcrmg
ID: 41823745
thank you
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

829 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