locked
How to concatenate two columns in a DataTable? RRS feed

  • Question

  • Hi friend,

    the following code tries to concatenate two datacolumns and add that to a Displaymember property of the combobox.

    What i need to do is to add  "--" sign between BrandCode and ShortName columns as ive tried to do:

     private void frmInventoryItemAdmin_Load(object sender, EventArgs e)
     {
                DataTable dt;
    
                cmbStockTakeDate.Items.AddRange(dayNumbers);
                cmbStockTakeDate.SelectedIndex = 0;
    
                dt = ICSBLL.Brand.SearchAllBrands();
                cmbBrands.DataSource = dt;
    
                DataColumn dcCodeNName = new DataColumn("CodeNName");
                dcCodeNName.Expression = string.Format("{0}-{1}", "BrandCode", "ShortName");
                
                
                dt.Columns.Add(dcCodeNName);
                
    
                cmbBrands.DisplayMember = "codeNName";
                cmbBrands.ValueMember = "BrandID";
     }
    but it throw the exception: Cannot perform '-' operation on System.String and System.String.

    Therefore how do i add "--" sybol between brandCode and ShortName?

    thanks
    Friday, March 5, 2010 3:43 AM

Answers

All replies