Wrox Programmer Forums
|
Visual Basic 2008 Essentials If you are new to Visual Basic programming with version 2008, this is the place to start your questions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2008 Essentials section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 20th, 2010, 03:25 AM
Registered User
 
Join Date: Sep 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Escape some special characters

Hi all,

I want to search the word below from the mysql database. But that word has some special characters like '

So i've written a code for search it. but it doesn't work, because there are some special characters. this is the code.

da = New MySqlDataAdapter("Select * from fixedbasics where LType='" & Trim(ComboBox1.Text) & "'", con)


t,a'wd¾'iS - This is the word, i want to search by an combobox.

can you help me to correct this code.

Thanks
 
Old September 20th, 2010, 08:52 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Can you just use a parametrized query??

that way, it doesn't matter the weird chars, since they are completely handled by the database.
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
 
Old September 21st, 2010, 10:09 AM
Registered User
 
Join Date: Sep 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Escape special characters

No idea what you say. Can you explain it or give a sample?

Thanks
 
Old September 21st, 2010, 10:30 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Well, you didn't say anything about the database you are using. But using an SP you can fill your adapter with a command object and pass the needed parameter to that command object. You can do it also supplying directly the SQL to the command object.

So, When you initialize the adapter, you are supplying the select command text. Instead of filling the data, just use a place holder (the appropriate according to your database) and then fill the adapter.selectcommand.parameters with the value you need.
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
 
Old September 23rd, 2010, 11:18 AM
Registered User
 
Join Date: Sep 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Escape special characters

Hi,

Finally i found the method, that i want. here is the code.

da = New MySqlDataAdapter("Select * from fixedbasics where LType='" & Trim(ComboBox1.Text..Replace("'", "''");) & "'", con)

Thanks.





Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL vs ASP.NET..escape characters haunting Quick209 ASP.NET 2.0 Basics 0 May 17th, 2006 03:26 PM
XML escape characters ACE2084 XML 0 September 9th, 2005 03:12 PM
storing special special characters in nvarchar... ACE2084 SQL Server 2000 2 February 9th, 2005 11:45 AM
how to escape special characters? reddygaru XML 2 December 16th, 2003 07:13 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.