trim functions, character arrays, strange errors

Results 1 to 2 of 2

Thread: trim functions, character arrays, strange errors

  1. #1
    Join Date
    Dec 1969

    Default trim functions, character arrays, strange errors

    I have a function for dynamically building a SQL string. when I am finished building this string I need to trim the last "AND " off of the end of it. I can&#039;t get any of the string functions to work on this string. I can&#039;t even trim the white space off the end. Aside from those problems, I get a strange error when defining a character array for my trim characters. When I use:<BR><BR>char[] trimAnd = {&#039;A&#039;,&#039;N&#039;,&#039;D&#039;,&#039 ; &#039;};<BR><BR>I get:<BR><BR>Configuration Error <BR>Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. <BR><BR>Parser Error Message: Could not load type $$struct0x6000002-1 from assembly myAssembly, Version=1.0.1451.16708, Culture=neutral, PublicKeyToken=null because the format is invalid.<BR><BR>Source Error: <BR><BR><BR>Line 256: &#060;add assembly="System.EnterpriseServices, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/&#062;<BR>Line 257: &#060;add assembly="System.Web.Mobile, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/&#062;<BR>Line 258: &#060;add assembly="*"/&#062;<BR>Line 259: &#060;/assemblies&#062;<BR>Line 260:<BR><BR><BR>Source File: c:windowsmicrosoft.netframeworkv1.1.4322Configmach ine.config Line: 258 <BR><BR><BR><BR>I actually get this error for an array of any characters over 2 characters in length. This error occurs on both my testing server and my live server.<BR><BR><BR>here is my whole function:<BR><BR>public void Search(object o, EventArgs e)<BR>{<BR>string sqlSearch = "SELECT * FROM myTable WHERE ";<BR><BR>string sqlSubject = "";<BR>string sqlDescription = "";<BR><BR><BR>foreach(string term in txtSearchTerms.Text.Split(new char[] {&#039; &#039;}))<BR>{<BR>sqlSubject += "subject LIKE &#039;%" + term + "%&#039; AND ";<BR>}<BR><BR>char[] trimAnd = {&#039;A&#039;,&#039;N&#039;,&#039;D&#039;,&#039 ; &#039;};<BR><BR>foreach(string term in txtSearchTerms.Text.Split(new char[] {&#039; &#039;}))<BR>{<BR>sqlDescription += "description LIKE &#039;%" + term + "%&#039; AND ";<BR>}<BR><BR>sqlSearch += sqlSubject + " OR " + sqlDescription;<BR><BR>Response.Write(sqlSearch);< BR>}<BR><BR><BR><BR>I know the code isn&#039;t very clean and doesn&#039;t look like it does much but I have to get the basics working before I can actually do anything. I can&#039;t get the trim functions to work period and that&#039;s why they are not currently in this block of code. I have another app that one works in so I&#039;m not sure what I&#039;m doing wrong. If anyone knows why I am getting this error or what I am doing wrong please, please help. I am at a loss. I am developing on an XP machine with Visual Studio .NET. Thanks in advance.<BR><BR>Jeff<BR><BR>

  2. #2

    Default RE: trim functions, character arrays, strange erro

    Start you query with string sqlSearch = "SELECT * FROM myTable WHERE AND 1=1";<BR>Then you can append your criteria without trailing an "AND"<BR><BR>sqlDescription += " AND description LIKE &#039;%" + term + "%&#039;";<BR><BR>And beware of SQL Injection

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts