Click here to Skip to main content
15,894,720 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Try
Dim asql As String = ("SELECT groupname FROM tblaccountgroup")
Dim da As New OleDbDataAdapter(asql, cnnOLEDB)
Dim ds As New DataSet
da.Fill(ds)
Cmbogroup.ValueMember = "groupname"
Cmbogroup.DataSource = ds.Tables(0)
Cmbogroup.SelectedIndex = 0
Catch ex As Exception
MsgBox("ERROR : " & ex.Message.ToString)
End Try
Posted
Comments
Richard Deeming 3-Jun-15 5:18am    
What does "remove trial space" mean?
Andy Lanng 3-Jun-15 5:25am    
Do you mean "Trailing whitespace"?
Dim asql As String = ("SELECT LTRIM(RTRIM(groupname)) FROM tblaccountgroup")
CHill60 3-Jun-15 5:44am    
I believe you're right - but like the question earlier, originating data may be wrong, OP may have a empty groupname in their datasource. I would post this as a solution

1 solution

(Ok Chill ^_^)

Do you mean "Trailing whitespace"?

You should always sanitize your data going into your database. You can use the c# & VB mystring.Trim() to clean white-spaces of your data going into the database.

Failing that, the data is now in the database with leading or trailing white-spaces. Clean the data in the select statement:

VB
Try
  Dim asql As String = ("SELECT LTRIM(RTRIM(groupname)) FROM tblaccountgroup")
  Dim da As New OleDbDataAdapter(asql, cnnOLEDB)
  Dim ds As New DataSet
  da.Fill(ds)
  Cmbogroup.ValueMember = "groupname"
  Cmbogroup.DataSource = ds.Tables(0)
  Cmbogroup.SelectedIndex = 0
Catch ex As Exception
  MsgBox("ERROR : " & ex.Message.ToString)
End Try


Hope that helps ^_^
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900