如何使用Sql server中的insert语句将html代码插入表中 [英] How to insert html code into table using insert statement in Sql server
问题描述
我试图使用sql查询将以下html代码插入到列中,但是Arial附近的语法错误不正确消息即将到来。由于打开单个代码和关闭单个代码不匹配,会出现此错误。
请帮助我使用sql server
A。 住宿甲板和SCR室的空调系统
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
A。 住宿甲板和SCR室的空调系统
A. Air Conditioning System of Accommodation Decks & SCR Room
推荐答案
您可以使用参数插入。检查下面的示例代码
you can use parameter to insert. check below sample code
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();
}
用单引号代替HTML代码(')用('')然后尝试插入
例如
Hi,
replace HTML code with single quote (') with ('') then try to insert
e.g.
hi, It's holiay today
替换'with''语句后如下...
after replace ' with '' statement will like below...
hi, It''s holiay today
插入时...
when insert...
Insert into tblname (colname) values(' hi, It''s holiay today ')
快乐编码!
:)
Happy Coding!
:)
这篇关于如何使用Sql server中的insert语句将html代码插入表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!