data problems

  • Thread starter Thread starter Jerry
  • Start date Start date
J

Jerry

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
 
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();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top