inserting HTML into SQL Server

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

David Browne

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
 
W

William Ryan

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

Marc Scheuner [MVP ADSI]

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
 

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

Top