473,387 Members | 1,711 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

string problems

Hi,

I am not sure if this the correct group to ask or not, but here it goes. I
am having problems inserting data into MS SQL 2005 vai c#.

I have strings( varchar( 80 )), that have ' and " in them:

'Danny's Place'

' 1' 1/2" '

How do I get SQL in c# to take varchar with ' & " ?

I have found issues in creating column names with / & % as well. Any ideas?

Thanks,

Jerry
Feb 13 '07 #1
5 1942
Hello jerry,

jI am not sure if this the correct group to ask or not, but here it
jgoes. I am having problems inserting data into MS SQL 2005 vai c#.
j>
jI have strings( varchar( 80 )), that have ' and " in them:
j>
j'Danny's Place'
j>
j' 1' 1/2" '
j>
jHow do I get SQL in c# to take varchar with ' & " ?

use the second ' sign

---
WBR, Michael Nemtsev [C# MVP].
My blog: http://spaces.live.com/laflour
Team blog: http://devkids.blogspot.com/

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
Feb 13 '07 #2
Michael,

"Michael Nemtsev" <ne*****@msn.comwrote in message
news:a2***************************@msnews.microsof t.com...
Hello jerry,

jI am not sure if this the correct group to ask or not, but here it
jgoes. I am having problems inserting data into MS SQL 2005 vai c#.
jjI have strings( varchar( 80 )), that have ' and " in them:
jj'Danny's Place'
jj' 1' 1/2" '
jjHow do I get SQL in c# to take varchar with ' & " ?

use the second ' sign
I do not understand, can you give me some examples?

Thank,

Jerry
>
---
WBR, Michael Nemtsev [C# MVP]. My blog: http://spaces.live.com/laflour
Team blog: http://devkids.blogspot.com/

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo


Feb 13 '07 #3
Hi,

Use parameters, it will solve your problem as well as prevent SQL Injections
attacks.
--
Ignacio Machin
machin AT laceupsolutions com

"Jerry" <jp******@general-steel.comwrote in message
news:12*************@corp.supernews.com...
Hi,

I am not sure if this the correct group to ask or not, but here it goes. I
am having problems inserting data into MS SQL 2005 vai c#.

I have strings( varchar( 80 )), that have ' and " in them:

'Danny's Place'

' 1' 1/2" '

How do I get SQL in c# to take varchar with ' & " ?

I have found issues in creating column names with / & % as well. Any
ideas?

Thanks,

Jerry


Feb 13 '07 #4
Hello jerry,
>jjHow do I get SQL in c# to take varchar with ' & " ?
use the second ' sign
jI do not understand, can you give me some examples?
j>

http://www.kamath.com/codelibrary/cl003_apostrophe.asp

But as Ignacio already told u, the params is the best way (depending on what
are u doing)

---
WBR, Michael Nemtsev [C# MVP].
My blog: http://spaces.live.com/laflour
Team blog: http://devkids.blogspot.com/

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
Feb 13 '07 #5
Amen!
The standard T-SQL escape character for a single quote is to put two single
quotes together , e.g. ('').
This tells SQL server to treat the second one as a literal part of the
string, instead of thinking it is the end marker for the string.
Ignacio is so right. Use parameters!

Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,

Use parameters, it will solve your problem as well as prevent SQL Injections
attacks.
--
Ignacio Machin
machin AT laceupsolutions com

"Jerry" <jp******@general-steel.comwrote in message
news:12*************@corp.supernews.com...
Hi,

I am not sure if this the correct group to ask or not, but here it goes. I
am having problems inserting data into MS SQL 2005 vai c#.

I have strings( varchar( 80 )), that have ' and " in them:

'Danny's Place'

' 1' 1/2" '

How do I get SQL in c# to take varchar with ' & " ?

I have found issues in creating column names with / & % as well. Any
ideas?

Thanks,

Jerry


Feb 13 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Susan Baker | last post by:
Hi, I have declared a class MyClass in a header file MyClass.h I have then gone onto define the class in MyClass.cpp. This is (roughly) what the definition (.cpp) file looks like: #include...
17
by: Olivier Bellemare | last post by:
I've tried to make a function that returns the middle of a string. For example: strmid("this is a text",6,4); would return "is a". Here is my code: char *strmid(char *texte, int depart,...
18
by: Steve Litvack | last post by:
Hello, I have built an XMLDocument object instance and I get the following string when I examine the InnerXml property: <?xml version=\"1.0\"?><ROOT><UserData UserID=\"2282\"><Tag1...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
10
by: zahy[dot]bnaya[At]gmail[dot]com | last post by:
Hi, I am trying to come up with a c style string reverser, I want it to take 1 argument Altough I would never do this in real life. Is there a way to do it? I wrote this function that fails : ...
3
by: sernamar | last post by:
Hi, I have the following base class class UnitOfMeasure { public: //... std::string& GetName() {return _uomName;}; //... protected:
42
by: =?Utf-8?B?UGxheWE=?= | last post by:
I have an if statement that isn't working correctly and I was wondering how I check for a blank string. My Code Example if me.fieldname(arrayIndex) = "" then ----- end if When I do this and...
3
by: ommail | last post by:
Hi I wonder if regular expressions are in general sower than using classes like String and Char when used for validating/parsing text data? I've done some simple test (using IsMatch()) method...
14
by: Javier | last post by:
Hello, in which cases is it better the use of "const char*" to "string" (or even const string &). I mean, in STL (http://www.sgi.com/tech/stl/hash_map.html) I see: hash_map<const char*, int,...
21
by: phpCodeHead | last post by:
Code which should allow my constructor to accept arguments: <?php class Person { function __construct($name) { $this->name = $name; } function getName()
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.