Click here to Skip to main content
15,903,817 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
dear friends

i have a problem in the query/logic
iam saving the complete path of my files say
c:\mysyncfolder\hello\abc.txt
c:\mysyncfolder\hello123\abc1.txt
in case the user is renaming the folder say 'hello' to 'hello1'

i want to update the path in the database



but it is also returning the folders hello123. with hello folder
how can i solve this problem

What I have tried:

currently iam using following query
Select * from FileInformation Where FilePath like '" + myPath + "%' And Status<>'Deleted'
Posted
Updated 16-Feb-16 23:31pm
v2
Comments
dharan1990 17-Feb-16 5:40am    
Since you are using like both records will be pulled if you want to check for specific keyword try using contains in sql.

If you are trying to select "whole folder names" only, then use explicit backslashes:
SQL
SELECT * FROM FileInformation Where FilePath LIKE '" + myPath.Trim('\\') + "\\%'" AND Status <> 'Deleted'
But please, don't do it like that.
Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.
 
Share this answer
 
v3
Two ways I can think of:

Use the '_' wildcard. It is a single char wildcard unlike '%' which is 0 to many chars.

Or you can look for the closest match, which it your case will be the shortest filepath.

You won't be able to tell the difference between hello1.txt and helloz.txt
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900