私のcomboBoxのトリミングは、SQL Serverからデータを取得しようとしていますか?トリム機能を使用する必要があることに注意してください。私はさまざまな方法でそれを適用しましたが、まだ私のデータベースから空白に直面しているようです。 Trim機能を効果的に組み込むにはどうすればいいですか?私のC#アプリケーションからのSQLデータベース値の切り取り
void fill()//fill combobox with values
{
try
{
string connectionString = "Data Source=cmcentraldb;Initial Catalog=CMLTD;Integrated Security=True";
SqlConnection con2 = new SqlConnection(connectionString);
con2.Open();
string query = "SELECT DISTINCT ITEMDESC FROM dbo.IV00101";
//select Convert(nvarchar(50),Item_Description)+ ':' +Convert(nvarchar(50),Item#) as Combined from Carimed
SqlCommand cmd2 = new SqlCommand(query, con2);
SqlDataReader dr2 = cmd2.ExecuteReader();
while (dr2.Read())
{
string cari_des = dr2.GetString(dr2.GetOrdinal("ITEMDESC"));
suggestComboBox1.Items.Add(cari_des);
suggestComboBox1.Text.Trim();
}
//con2.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
データベーステーブルのデータ型とは何ですか。その固定されたcharの場合、サイズに関係なく常に同じ量の領域が割り当てられます。 – Wheels73
'suggestComboBox1.Items.Add(cari_des.Trim()); ' – MotKohn
私はそれがcharだと知っていますが、私はデータベースに対する管理権限がないということです。特定の列から引っ張って、アプリケーション内でトリムしようとしています@ Wheels73 –