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?
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
The combobox SelectedIndexChanged method
Thanks in advance
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
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"
Code:
System.Console.WriteLine("Contents of ComboBox " + ComboBox1.SelectedText)
Thanks in advance