PC Review


Reply
Thread Tools Rate Thread

data problems

 
 
Jerry
Guest
Posts: n/a
 
      13th Feb 2007
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


 
Reply With Quote
 
 
 
 
=?Utf-8?B?Q2lhcmFuIE8nJ0Rvbm5lbGw=?=
Guest
Posts: n/a
 
      13th Feb 2007
use parameters or replace ' with '' (two of them) and " with ""
Parameters are the proper way to do it though.
e.g

SqlCommand sqlcom = new SqlCommand("insert into table1 (col1, col2) values
(@value1, @value2), new SqlConnection(constring);
sqlcom.Parameters.AddWithValue("@value1", "Danny's Place");
sqlcom.Parameters.AddWithValue("@value2", " 1' 1/2\"");

sqlcom.Connection.Open();
sqlcom.ExecuteNonQuery();
sqlcom.Connection.Close();


--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com


"Jerry" wrote:

> 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
>
>
>

 
Reply With Quote
 
Ignacio Machin \( .NET/ C# MVP \)
Guest
Posts: n/a
 
      13th Feb 2007
Hi,

See the other thread you posted.

"Jerry" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Data validation causing problems when using a data form in Excel2 Debra Dalgleish Microsoft Excel Worksheet Functions 0 27th Nov 2009 12:00 AM
split data problems Access G-man Microsoft Access Queries 8 31st Jan 2008 01:07 PM
Problems with an ' in my data =?Utf-8?B?UmF5?= Microsoft Access 3 11th Jan 2007 04:48 AM
Data Problems Kevin Microsoft ADO .NET 3 8th Apr 2005 12:49 AM
Problems with data types Steve Microsoft Access Queries 2 27th Sep 2004 12:24 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:17 AM.