Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

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't get any of the string functions to work on this string. I can'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:

 

char[] trimAnd = {'A','N','D',' '};

 

I get:

 

Configuration Error

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.

 

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.

 

Source Error:

 

 

Line 256: <add assembly="System.EnterpriseServices, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>

Line 257: <add assembly="System.Web.Mobile, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>

Line 258: <add assembly="*"/>

Line 259: </assemblies>

Line 260:

 

 

Source File: c:\windows\microsoft.net\framework\v1.1.4322\Config\machine.config Line: 258

 

 

 

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.

 

 

here is my whole function:

public void Search(object o, EventArgs e)
{
string sqlSearch = "SELECT * FROM myTable WHERE ";

string sqlSubject = "";
string sqlDescription = "";


foreach(string term in txtSearchTerms.Text.Split(new char[] {' '}))
{
sqlSubject += "subject LIKE '%" + term + "%' AND ";
}

char[] trimAnd = {'A','N','D',' '};

foreach(string term in txtSearchTerms.Text.Split(new char[] {' '}))
{
sqlDescription += "description LIKE '%" + term + "%' AND ";
		}

sqlSearch += sqlSubject + " OR " + sqlDescription;

Response.Write(sqlSearch);
}

 

 

I know the code isn't very clean and doesn't look like it does much but I have to get the basics working before I can actually do anything. I can't get the trim functions to work period and that's why they are not currently in this block of code. I have another app that one works in so I'm not sure what I'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.

 

Jeff

Edited by PlausiblyDamp
Posted
This doesnt resolve your particular error. But why not create your array of keywords then do a For...I..Next loop and check for when i = ubound of your array, and if it does, leave out the 'AND'.
Posted
Well, the error from the character array has dissappeared. yes dissappeared. I didn't change anything, it just went away. however, the trim functions still do not work. I can think of several work arounds for this particular problem, but I would really like to use the trim functions as they are the easiest and should work. any ideas?
Posted (edited)

her is the code I have at the moment. there are a lot string function calls in it right now because I'm trying to find out what works and what doesn't so I can better locate the source of the problem.

public void Search(object o, EventArgs e)
{
string sqlSearch = "SELECT * FROM myTable WHERE ";

string sqlSubject = "";
string sqlDescription = "";

foreach(string term in txtSearchTerms.Text.Split(new char[] {' '}))
{
sqlSubject += "subject LIKE '%" + term + "%' AND ";
}

char[] trimAnd = {'A','N','D',' '};

sqlSubject.TrimEnd(new char[] {'A','N','D',' '});

sqlSubject.Trim(trimAnd);

sqlSubject.Replace("AND ", "and");

sqlSubject.ToLower();

foreach(string term in txtSearchTerms.Text.Split(new char[] {' '}))
{
sqlDescription += "description LIKE '%" + term + "%' AND ";
}

sqlSearch += sqlSubject + " OR " + sqlDescription;
Response.Write(sqlSearch);
}

 

here is the sqlSearch string I get from the response.write when i use "hi hello" as the search string.

 

SELECT * FROM myTable WHERE subject LIKE '%hi%' AND subject LIKE '%hello%' AND OR description LIKE '%hi%' AND description LIKE '%hello%' AND 

 

The TrimEnd should remove the "AND " in the "AND OR", the Trim should actually remove all the instances of "AND ", the replace should change all instances of "AND" to "and", my final desperate attempt was to see if they could all be chaned to lowercase, just to test.

 

as you can see, none of them work. This is a reallly strange problem to have. Thanks for looking at this.

Edited by PlausiblyDamp

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...