inserting HTML into SQL Server

  • Thread starter Thread starter Mitch Abaza
  • Start date Start date
M

Mitch Abaza

I've got a simple SQL Server 2000 table with an ntext field defined and I'm
having a heck of a time inserting html into it. Everytime I try, I get an
ADO.NET error complaining about invalid syntax because its trying to parse
out the various HTML tags (>,<,+, =) and it's puking. Is there a way to
disable this behavior?

Thanks!
 
Mitch Abaza said:
I've got a simple SQL Server 2000 table with an ntext field defined and I'm
having a heck of a time inserting html into it. Everytime I try, I get an
ADO.NET error complaining about invalid syntax because its trying to parse
out the various HTML tags (>,<,+, =) and it's puking. Is there a way to
disable this behavior?

Don't try to build a SQL query to insert it.

Use a command with a parameter, instead.

SqlCommand cmd = new SqlCommand("insert into foo(v) values (@v)");
cmd.parameters.add(. . .

cmd.ExecuteNonQuery()

David
 
Are you passing in your HTML as a Parameter? It should escape it if you do,
however your length will be limited by the DB field. You may also want to
try storing it as binary...it shouldn't bark at you and you can get quite a
bit of data into it.
 
Don't try to build a SQL query to insert it.
Use a command with a parameter, instead.

Or better yet - use a stored procedure to insert and retrieve the HTML
stuff !

Marc
================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
 
Back
Top