Question Strange spaces in bound combobox

Zvi

Member
Joined
Sep 30, 2006
Messages
16
Programming Experience
Beginner
The fields of first and last name are set to varchar(15) to eliminate the empty spaces but when running, the names in the combobox have a weird spacing issue. What's wrong?

I'm using VS 2015, VBnet windows form.
 

Attachments

  • 2016-03-29 08_09_10-New Project Setup.png
    2016-03-29 08_09_10-New Project Setup.png
    2.5 KB · Views: 47
What's your query for getting the records?
Do you Trim() each varchar field's data before it goes into the database?
 
What's your query for getting the records?
Do you Trim() each varchar field's data before it goes into the database?

UPDATE: I've managed to get the text aligned by using a fixed font (eg: courier) but now I still have the trailing spaces in the combo although the SQL is using VARCHAR which is supposed to hide the trailing spaces.

In the FORM_LOAD I tried without trim, which gives me the following result: (has extra spaces after first and last name)
2016-04-16 08_58_56-New Project Setup.png

VB.NET:
Me.VINEWOODSTUDIOS_DataSet.tbl_clients.Columns.Add("FullName", GetType(String), "client_id +' ' + client_first_name + client_last_name")
        Me.Tbl_clientsTableAdapter.Fill(Me.VINEWOODSTUDIOS_DataSet.tbl_clients)
        ComboBox_clients.DisplayMember = "FullName"

I'm not sure how to implement the TRIM function in the Query. I tried LTRIM and RTRIM but this doesn't help: (example of RTRIM:)

VB.NET:
Me.VINEWOODSTUDIOS_DataSet.tbl_clients.Columns.Add("FullName", GetType(String), "client_id +' ' + RTRIM(client_first_name) + RTRIM(client_last_name)")
        Me.Tbl_clientsTableAdapter.Fill(Me.VINEWOODSTUDIOS_DataSet.tbl_clients)
        ComboBox_clients.DisplayMember = "FullName"
 
I posted it:

Me.VINEWOODSTUDIOS_DataSet.tbl_clients.Columns.Add("FullName", GetType(String), "client_id +' ' + client_first_name + client_last_name")
 
I posted it:

No you didn't. That's not your query. Your query is the SELECT statement that gets the data from the database in the first place.
 
I don't use a query for getting the data from the database. The dataset in VB gets it with a table adopter and the combo box is bound to the dataset.
 
I don't use a query for getting the data from the database.
Yes you do.
The dataset in VB gets it with a table adopter and the combo box is bound to the dataset.
Neither the DataSet nor the table adapter are magic. The table adapter contains your query.

That said, if you don't even know that the query exists then it would follow that it was generated automatically, which means it wouldn't contain anything exotic. I suggest that you have a look at the parameters that correspond to that column in the InsertCommand and UpdateCommand of that table adapter. They will have a property that indicates the database data type. What is that data type?
 
Ok. Is this what you asked for?

VB.NET:
<DbCommand CommandType="Text" ModifiedByUser="false">
                    <CommandText>SELECT client_id, client_cell_num, client_company_name, client_email, client_first_name, client_last_name, client_work_num, client_zehut_num FROM tbl_clients</CommandText>
                    <Parameters />

It's from the dataset.xsd file

This is from the tabaleadaptor:

VB.NET:
SELECT client_id, client_cell_num, client_company_name, client_email, client_first_name, client_last_name, client_work_num, client_zehut_num FROM tbl_clients


The first and last names are VARCHAR[15]
 
Ok. Is this what you asked for?

VB.NET:
<DbCommand CommandType="Text" ModifiedByUser="false">
                    <CommandText>SELECT client_id, client_cell_num, client_company_name, client_email, client_first_name, client_last_name, client_work_num, client_zehut_num FROM tbl_clients</CommandText>
                    <Parameters />

It's from the dataset.xsd file

This is from the tabaleadaptor:

VB.NET:
SELECT client_id, client_cell_num, client_company_name, client_email, client_first_name, client_last_name, client_work_num, client_zehut_num FROM tbl_clients


The first and last names are VARCHAR[15]

That's what I was originally after but I concluded that it would likely not help, as I said in my previous post. I also asked for some other information in my previous post.
 
Here's the INSERT command of the dataset: (The type is ansistring. provider type is varchar - like I setup in SQL command).

VB.NET:
<InsertCommand>
                  <DbCommand CommandType="Text" ModifiedByUser="false">
                    <CommandText>INSERT INTO [tbl_clients] ([client_cell_num], [client_company_name], [client_email], [client_first_name], [client_last_name], [client_work_num], [client_zehut_num]) VALUES (@client_cell_num, @client_company_name, @client_email, @client_first_name, @client_last_name, @client_work_num, @client_zehut_num);
SELECT client_id, client_cell_num, client_company_name, client_email, client_first_name, client_last_name, client_work_num, client_zehut_num FROM tbl_clients WHERE (client_id = SCOPE_IDENTITY())</CommandText>
                    <Parameters>
                      <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="AnsiString" Direction="Input" ParameterName="@client_cell_num" Precision="0" ProviderType="VarChar" Scale="0" Size="0" SourceColumn="client_cell_num" SourceColumnNullMapping="false" SourceVersion="Current" />
                      <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="AnsiString" Direction="Input" ParameterName="@client_company_name" Precision="0" ProviderType="VarChar" Scale="0" Size="0" SourceColumn="client_company_name" SourceColumnNullMapping="false" SourceVersion="Current" />
                      <Parameter AllowDbNull="false" AutogeneratedName="" DataSourceName="" DbType="AnsiString" Direction="Input" ParameterName="@client_email" Precision="0" ProviderType="VarChar" Scale="0" Size="0" SourceColumn="client_email" SourceColumnNullMapping="false" SourceVersion="Current" />
                      <Parameter AllowDbNull="false" AutogeneratedName="" DataSourceName="" DbType="AnsiString" Direction="Input" ParameterName="@client_first_name" Precision="0" ProviderType="VarChar" Scale="0" Size="0" SourceColumn="client_first_name" SourceColumnNullMapping="false" SourceVersion="Current" />
                      <Parameter AllowDbNull="false" AutogeneratedName="" DataSourceName="" DbType="AnsiString" Direction="Input" ParameterName="@client_last_name" Precision="0" ProviderType="VarChar" Scale="0" Size="0" SourceColumn="client_last_name" SourceColumnNullMapping="false" SourceVersion="Current" />
                      <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="AnsiString" Direction="Input" ParameterName="@client_work_num" Precision="0" ProviderType="VarChar" Scale="0" Size="0" SourceColumn="client_work_num" SourceColumnNullMapping="false" SourceVersion="Current" />
                      <Parameter AllowDbNull="false" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="Input" ParameterName="@client_zehut_num" Precision="0" ProviderType="Int" Scale="0" Size="0" SourceColumn="client_zehut_num" SourceColumnNullMapping="false" SourceVersion="Current" />
                    </Parameters>
                  </DbCommand>
                </InsertCommand>
 
Back
Top