Reputation: 897
I'm loading data from a table into a textbox and I'm getting spaces. I tried putting rtrim in the select statement but when I do that I get an error saying "column does not belong to table." I also tried doing textbox.text.trim() and that does not remove the spaces either. Any help would be appreciated.
SqlCommand sqlcom = new SqlCommand("SELECT rtrim(firstname), lastname, address, addresstwo, city, state, zip, phone, email FROM CustomerTbl WHERE customerrid =" + intCustomerid, AppClass.thisConnect);
SqlDataReader sqldataR = sqlcom.ExecuteReader();
DataTable dt = new DataTable("customer");
dt.Load(sqldataR);
AppClass.thisConnect.Close();
txtFirstname.Text = dt.Rows[0]["firstname"].ToString();
Upvotes: 1
Views: 1696
Reputation: 4619
Add an AS
clause to your SELECT
statement.
SELECT rtrim(firstname) AS trimmedFirstName
for instance. Then make sure to use that column name in your code.
txtFirstname.Text = dt.Rows[0]["trimmedFirstName"].ToString();
Upvotes: 4