简体   繁体   中英

C# - Combobox Items contain spaces after importing from dataset

I was wondering if someone could tell me why when I populate my combobox from a dataset with several columns, there are spaces(about 5 spaces) in each row between the column values.

code

thisConnect.Open();

SqlDataAdapter sqladapt = new SqlDataAdapter("SELECT firstname, lastname, address FROM OwnersTbl", thisConnect);

DataSet ds = new DataSet();

sqladapt.Fill(ds, "OwnersTbl");

thisConnect.Close();

for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
  comboBoxOwners.Items.Add(ds.Tables[0].Rows[i][0] + "" + ds.Tables[0].Rows[i][1] + "" + ds.Tables[0].Rows[i][2]);
}

As the comment. If it is char(30) then you will get 30 characters.
Try

select rtrim(firstname) ...

OR

ds.Tables[0].Rows[i][0].Trim()

And it is not always better to go varchar.
If the values are initially empty and you add then can cause page splits.
But a char(30) will hold that space.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM