Results 1 to 5 of 5

Thread: [RESOLVED] Concatenate two NChar data type columns

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2018
    Posts
    90

    Resolved [RESOLVED] Concatenate two NChar data type columns

    Dear all,
    I'm trying to bind an added data column to a Combobox.
    Therefore I'm adding a column to the datatable I'm using which is made by the concatenation of two fields. Unfortunately, as the two fields are of type NChar(50) the result is that in the combobox the two fields appear with a lot of empty spaces in between.

    Here below the code I'm using:

    Code:
    Dim Fullname As New DataColumn()
            Fullname.DataType = System.Type.GetType("System.Object")
            Fullname.ColumnName = "Fullname"
            CTO_DataSet.Tbl_CTOAbilità.Columns.Add("FullName", GetType(String), "Nome + Cognome")
    
            Cmb1.DataSource = CTO_DataSet.Tbl_CTOAbilità
            Cmb1.DisplayMember = "Fullname"
            Cmb1.ValueMember = "ID"
    For example, let's name field Nome is "Filippo" and Cognome is "Rossi", the result in the combobox is:
    "Filippo Rossi".

    How can I delete the spaces?

    Thanks for the support,
    A.

  2. #2
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,495

    Re: Concatenate two NChar data type columns

    I would add Trim of the fields in the SQL that you use to generate the data set.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2018
    Posts
    90

    Re: Concatenate two NChar data type columns

    Dear GaryMazzone,
    do you mean something like:

    Code:
    "SELECT Id,Codice,LTRIM(RTRIM(Nome)),LTRIM(RTRIM(Cognome)),Anno_di_nascita"
    Thanks,
    A.

  4. #4
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,495

    Re: Concatenate two NChar data type columns

    Yes... NCHAR data type always store the full size even if it is less
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Sep 2018
    Posts
    90

    Re: Concatenate two NChar data type columns

    Thanks - done and it works!

    A.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width