Hi Guys, I Have the a Select Query statement - that I need to remove White space from Columns (Autoname) and also Column (Title). Here is what I have so far - but it doesn't seem to be working...
Query = String.Format("SELECT AutoName,{0} FROM {1} WHERE AutoName like '{2}% " & Replace(Query, "'", "''") & "%' AND Title like '{3}% " & Replace(Query, "'", "''") & "%' OR AutoName like '{4}% " & Replace(Query, "'", "''") & "%' OR Title like '{4}% " &
Replace(Query, "'", "''") & "%' ORDER BY {5}", PrimaryKeyColumn, TableName, DDLCategory.SelectedItem.Text, DDLSubCategory.SelectedItem.Text, txtSearch.Text, SetSorting())
asp.netcat
Participant
1153 Points
438 Posts
Help Select Query Statement
Dec 11, 2011 08:15 AM|LINK
Hi Guys,
I Have the a Select Query statement - that I need to remove White space from Columns (Autoname) and also Column (Title).
Here is what I have so far - but it doesn't seem to be working...
Query = String.Format("SELECT AutoName,{0} FROM {1} WHERE AutoName like '{2}% " & Replace(Query, "'", "''") & "%' AND Title like '{3}% " & Replace(Query, "'", "''") & "%' OR AutoName like '{4}% " & Replace(Query, "'", "''") & "%' OR Title like '{4}% " & Replace(Query, "'", "''") & "%' ORDER BY {5}", PrimaryKeyColumn, TableName, DDLCategory.SelectedItem.Text, DDLSubCategory.SelectedItem.Text, txtSearch.Text, SetSorting())
Rab Nawaz Kh...
Participant
955 Points
209 Posts
Re: Help Select Query Statement
Dec 11, 2011 08:33 AM|LINK
I think you need to use Trim() method of string class
DDLCategory.SelectedItem.Text.Trim();
this will remove all the starting and ending white spaces from the string
Hope answer the question
Mark as answer if it helps
Mikesdotnett...
All-Star
154927 Points
19867 Posts
Moderator
MVP
Re: Help Select Query Statement
Dec 11, 2011 08:36 AM|LINK
Don't use string.Format to build you query. It's unsafe and a mess. Vile. Use parameters for dynamic values. http://www.mikesdotnetting.com/Article/113/Preventing-SQL-Injection-in-ASP.NET
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Help Select Query Statement
Dec 13, 2011 12:52 AM|LINK
Where's the white space for Autoname and Title?Do you mean your DataTables' columns having white space or ……?Your codes are hard for me to view。
Best reguards!