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.SelectedIndex = 0;
                dt = ICSBLL.Brand.SearchAllBrands();
                cmbBrands.DataSource = dt;
                DataColumn dcCodeNName = new DataColumn("CodeNName");
                dcCodeNName.Expression = string.Format("{0}-{1}", "BrandCode", "ShortName");
                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?

    Friday, March 5, 2010 3:43 AM


All replies