Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String Concatenation

Status
Not open for further replies.

jimbledon

Technical User
Dec 27, 2004
22
GB
Hi All,

Being Fairly new to SQL-Server, I have come up a couple of probems when binding a combobox to a table.

The first thing is the connection string being used concatentates the firstname and surname into a new string called CustName.
It works okay but because the fields are varchar(22) and varchar(24) respectively; when they appear in the combobox they are not next to each other.
Is there away to trim the strings to the absolute size?
Code:
SELECT CustID, CustSname + ' ' + CustfName AS 'CustName' FROM CustTable ORDER BY CustfName
The second thing is the valuemember item on the comboxbox, i cannot get the value to return as i want to input the value into a stored procedue to return a list of values.
Does anyone know what i have done wrong?

In the form load
Code:
Dim strSelectCustomers As String = "SELECT CustSname + ', ' + CustfName AS [CustName], CustID FROM CustTable ORDER BY CustfName"
        System.Console.WriteLine(strSelectCustomers)
        'MsgBox("SQL statement " + strSelectCustomers)
        Dim strConnString As String = "data source=(local);" & _
            "initial catalog=Project;integrated security=SSPI;"
        Dim daCustomers As New SqlDataAdapter(strSelectCustomers, strConnString)
        Dim dsCustomers As New DataSet

        daCustomers.Fill(dsCustomers, "dtCustomerTable")
        'MsgBox(dsCustomers.GetXml, , "Results of Customer DataSet in XML")

        ComboBox1.DataSource = dsCustomers.Tables("dtCustomerTable")
        ComboBox1.ValueMember = "CustID"
        ComboBox1.DisplayMember = "CustName"
The combobox SelectedIndexChanged method
Code:
System.Console.WriteLine("Contents of ComboBox " + ComboBox1.SelectedText)

Thanks in advance
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top