Click here to Skip to main content
15,893,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I am trying to insert into following html code into a column using sql query but "incorrect syntax error near Arial" message is coming. This error is coming because of mismatch of opening single code and closing single code.

Please help me to insert bulk of html code like below into table using sql server

"

A. Air Conditioning System of Accommodation Decks & SCR Room

"

insert into Quatations value('

A. Air Conditioning System of Accommodation Decks & SCR Room

')




Thanks,
Santosh
Posted
Updated 9-Dec-19 19:47pm

you can use parameter to insert. check below sample code

C#
using (var conn = new SqlConnection("some conn string"))
using (var cmd = conn.CreateCommand())
{
    conn.Open();
    cmd.CommandText = "insert into Table1 (ColumnName) values (@inputHtml)";
    cmd.Parameters.AddWithValue("@inputHtml", inputHtml);
    cmd.ExecuteNonQuery();
}
 
Share this answer
 
Comments
santoshkumar413 14-May-14 2:30am    
yeah it also works

Thanks for Your Reply
Hi,

replace HTML code with single quote (') with ('') then try to insert

e.g.
 hi, It's holiay today 

after replace ' with '' statement will like below...
 hi, It''s holiay today 

when insert...
SQL
Insert into tblname (colname) values(' hi, It''s holiay today ')

Happy Coding!
:)
 
Share this answer
 
Comments
santoshkumar413 14-May-14 1:48am    
But I need to retrieve the record again, after retrieving I need the same format which I have inserted. I need a query which will insert any html content into table irrespective of no. of codes or no. of braces etc.....means inserting whole html data into column like....<html><body><p style='Color:Red;Font-Size:2px'>xyz xyz xyz</p>
<image src="~xyz/xyz.png" alt="image"/>
</body></html>
Aarti Meswania 14-May-14 2:11am    
yes you will get same format
Aarti Meswania 14-May-14 2:14am    
DECLARE @Temptbl table (col Nvarchar(200))
INSERT INTO @Temptbl (col)
VALUES('<html><body><p style=''Color:Red;Font-Size:2px''>xyz xyz xyz</p><image src="~xyz/xyz.png" alt="image"/></body></html>')
SELECT * FROM @Temptbl

run this and check output
santoshkumar413 14-May-14 2:14am    
Hi, thanks for your reply, I found the solution for that, wrote stored procedure and passed parameter into the stored procedure from .cs page in .net
Aarti Meswania 14-May-14 2:30am    
ok store-procedure was the best way to do this :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900