Click here to Skip to main content
15,905,322 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
OleDbDataAdapter da = new OleDbDataAdapter("select * from LOGIN where U_name='" + User + "' And  U_password='" + Password + "' ", con);


when i put d'souza it gives me an error
Posted
Comments
Richard C Bishop 19-Apr-13 15:21pm    
It reads the single quote in that name as an indicator to begin or end a string. You cannot use that. Double it up to escape the single quote and that should work.
joshrduncan2012 19-Apr-13 15:25pm    
Rich is correct. However, this would have been a great question to ask google. To use the single quote in the name, you will have to replace the single quote with 2 single quotes. That should do the trick for you.

Try this hope it can help.......


C#
public static string DoQuotes(string sql)
       {
           if (sql == null)
               return "";
           else
               return sql.Replace("'", "''");
       }
 
Share this answer
 
That is because the single quote represent the end of the string so all of text after it is seen as malformed input. Do Replace("'","\\'") (C# version) on the user name to place an escape character before the single quote. In MySQL the espace character is a \ I'm not sure of what it is for your situation so you will have to double check. Please let me know if this doesn't work for you.
 
Share this answer
 
Hello Amirsalgar1,

Like richcb told you in the first comment, the problem is the ['] character in d'souza name.
I recommend you to use sql parameter object to avoid this kind of problem.
http://msdn.microsoft.com/en-us/library/bbw6zyha(v=vs.71).aspx[^]

Good luck.
JAFC
 
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