[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 53
  • Last Modified:

Combine two columns

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
mcrmg
Asked:
mcrmg
1 Solution
 
Ramkisan JagtapLead DeveloperCommented:
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
 
Ioannis ParaskevopoulosCommented:
What kind of error do you get?
0
 
mcrmgAuthor Commented:
thank you
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now