SQL search query !!!!

Discussion in 'Databases' started by ashrafcsnet, Jul 7, 2005.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. How we can search names from DB that includes ('s)... for exaple ... The name "ruler's " is in the DB under "Name" column in customers...

    cmd.CommandText="Select Name FROM Customers_Table WHERE Name='%" + txtName.Text + "%';
    da.SelectCommand=cmd;
    da.Fill(DS);

    this query is working unless if I enter names that includes ( ' ) --> "ruler's" it genarates an error !!!

    I NEED HELP PLEASE IF YOU WOULD MIND WRITING THE CODE HERE....
    Thanx alot...
     
  2. Replacing the single apostrophe for two apostrophes (not 1 quote) should do the trick for you.

    cmd.CommandText="Select Name FROM Customers_Table WHERE Name='%" + Replace(txtName.Text,"'","''") + "%';
     
  3. It's working 100% [​IMG] ... THANK YOU
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page