html - 将html和CSS放入数据库mmsql中

标签 html css sql-server

嗨,

我尝试将一些html和css作为MSSQL数据库中的记录。 我有这个:

IF NOT EXISTS (SELECT * FROM Beheer.EmailTemplateType WHERE Omschrijving = 'Wachtwoord vergeten')
BEGIN
    INSERT INTO Beheer.EmailTemplateType (Omschrijving, Html)
    VALUES
    (
        'Wachtwoord vergeten',      
        '<html> <head>  <link href="https://fonts.googleapis.com/css?family=Open+Sans:400,600,700" rel="stylesheet"><style type="text/css"> .td {font-family:"Open Sans", Arial, 'Helvetica Neue', Helvetica,  sans-serif;  color:#666666;  font-size:13px;     font-weight: normal;    line-height:150%;   letter-spacing: normal;     text-align:left;    } </style>   </head>  <body style="background-color: #ffffff; margin: 0; padding: 0;">    <!-- Snippet tekst. editable -->      <!--[if !gte mso 9]><!----><span style="display:none; font-size:0px; line-height:0px; max-height:0px; max-width:0px; opacity:0; overflow:hidden; visibility:hidden; mso-hide:all;">Nog één stap te gaan... </span><!--<![endif]-->        <table border="0" cellpadding="0" cellspacing="0" width="100%">  <tr>     <td align="center">      <!-- Logo. editable - extra cel tbv positionering in gmail app -->                     <table width="480" border="0" cellpadding="0" cellspacing="0" style="max-width: 480px;">        <tr>            <td align="left" width="270">           <div align="left" style="float: left; text-align: left;">           <img src="http://www.sdbayton.nl/wp-content/uploads/2016/12/mainlogo_274x122.png" align="left" border="0" style="float:left;">          </div>          </td>           <td align="left" width="210">&nbsp;</td>        </tr>       </table>                                            </td>  </tr>   <tr>     <td align="center" style="padding-top: 20px">        <!-- Koptekst en introtekst. editable -->                  <table width="480" border="0" cellpadding="0" cellspacing="0" style="max-width: 480px;">            <tr>                <td align="left">                       <h1 style="font-family: 'Open Sans', Arial, Helvetica, sans-serif; font-size: 16px; color:#666666; font-weight: normal; line-height: 100%; letter-spacing: normal; text-align: left;">Stel je wachtwoord opnieuw in </h1>                                       <p style="font-family: 'Open Sans', Arial, Helvetica, sans-serif; font-size: 13px; color:#666666; font-weight: normal; line-height: 150%; letter-spacing: normal; text-align: left;"> Beste {Voornaam},<br> <br> Er is via dit e-mailadres een aanvraag voor een nieuw wachtwoord gedaan. <br> <br> Klik op onderstaande button om deze aanvraag af te ronden. </p>                         </td>           </tr>       </table>                    </td>  </tr>  <tr>      <td align="center">         <table width="480" border="0" cellpadding="0" cellspacing="0" style="max-width: 480px;">            <tr>                <td align="left">                <!-- Button met call 2 action, niet editable - let op!!: 2 maal een href -->                                           <table width="100%" border="0" cellpadding="0" cellspacing="0" align="left">                <tr>                    <td bgcolor="#ffffff " align="left" style="padding: 20px 0px 20px 0px;">                        <div><!--[if mso]>                        <v:roundrect xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="urn:schemas-microsoft-com:office:word" href="http://testlink" style="height:40px;v-text-anchor:middle;width:200px;" arcsize="8%" stroke="f" fillcolor="#00b3e2 ">                           <w:anchorlock/>                             <center>                          <![endif]-->                            <a href="http://testlink"                         style="background-color:#00b3e2 ;border-radius:3px;color:#ffffff ;display:inline-block;font-family:sans-serif;font-size:13px;line-height:40px;text-align:center;text-decoration:none;width:200px;-webkit-text-size-adjust:none;">Wijzig je wachtwoord</a>                         <!--[if mso]>                             </center>                         </v:roundrect>                        <![endif]-->                           </div>                   </td>               </tr>           </table>      <!-- Optioneel tekstblok onder button, niet editable -->                  <table width="100%" border="0" cellpadding="0" cellspacing="0"  align="left">                   <tr>                        <td bgcolor="#ffffff " align="left">                            <p style="font-family: 'Open Sans', Arial, Helvetica, sans-serif; font-size: 13px; color:#666666; font-weight: normal; line-height: 150%; letter-spacing: normal; text-align: left;"> Deze link is eenmalig te gebruiken en 24 uur actief. Via de link <em>Wachtwoord vergeten</em> op het inlogscherm van {SDB Applicatienaam} is het altijd mogelijk een nieuw wachtwoord aan te vragen.<br> Doet de button het niet? Kopieer dan deze link naar je browser: {INLOGLINK} </p>                         </td>                   </tr>               </table>                                        </td>           </tr>           </table>                    </td>  </tr>    <tr>    <td align="center">       <!-- Tekstblok 2: afsluitend tekstje. editable -->                        <table width="480" border="0" cellpadding="0" cellspacing="0" style="max-width: 480px; padding-top:20px;">              <tr>                <td align="left">               <p style="font-family: 'Open Sans', Arial, Helvetica, sans-serif; font-size: 13px; color:#666666; font-weight: normal; line-height: 150%; letter-spacing: normal; text-align: left;"> Komt de aanvraag voor een nieuw wachtwoord niet bij jou vandaan? Dan mag je dit e-mailbericht negeren. <br> <br> <br> Met vriendelijke groet,<br> Het SDB Ayton Team                  </p>                                </td>           </tr>       </table>            </td>  </tr>                                <!-- td - padding-top voor witruimte  -->                                              <tr>     <td align="center" style="padding-top: 30px">        <!-- table 100% breed grijze backgroundkleur -->           <table cellpadding="0" cellspacing="0" width="100%">    <tr>        <td bgcolor="#f4f4f4" style="padding: 15px 0px 15px 0px;" align="center">                <!-- Footer. niet editable -->                                     <table width="480" border="0" cellpadding="0" cellspacing="0" style="max-width: 480px;">            <tr>                <td align="left">                                   <p align="left" style="font-family: 'Open Sans', Arial, Helvetica, sans-serif; font-size: 11px; color:#666666; font-weight: normal; line-height: 140%; letter-spacing: normal; text-align: left;"> Je ontvangt deze mail omdat je gebruik maakt van {SDB*Applicatienaam} via {TESTnaamwerkgever}. <br /> Dit is een automatisch bericht waar je niet op kunt antwoorden.<br> {SDB*Applicatienaam} is een dienst van SDB Ayton.                  </p>                                        </td>           </tr>           </table>                    </td>   </tr>   </table>        </td>  </tr>                   </table>      </body> </html> '



    )
END
GO

但是我在这一行收到错误:

{font-family:"Open Sans", Arial, 'Helvetica Neue'

Incorrect syntax near '', Arial, Helvetica, sans-serif; font-size: 16px; color:#666666; font-weight: normal; line-height: 100%; letter-spacing: normal; text-align: left;">

是因为我必须输入:

双括号中的“Helvetica Neue”?

像这样:

“Helvetica Neue”?

谢谢

最佳答案

由于输入字符串中存在单引号,您收到此错误。在 SQL 中,如果要插入单引号值,则必须将其指定为 2 个单引号。像这样

我想将字符串I'm a Programmer插入到我的表格中。

如果我使用以下内容,我会收到错误

INSERT INTO MyTable(Msg)
VALUES('I'm a Programmer')

所以,我必须这样写

INSERT INTO MyTable(Msg)
VALUES('I''m a Programmer')

因此,在您的应用程序中,在传递输入字符串(CSS、HTML 或任何内容)之前,只需将所有单引号 (') 替换为 2 个单引号 ('')

关于html - 将html和CSS放入数据库mmsql中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47767690/

相关文章:

sql - 没有标识列但此列不能有重复值的表

jquery - 使用 Jquery 在 Canvas 中单击两次鼠标绘制一条线

带有自定义 Google map 标记/放置动画的 Javascript

css - 如何在 Bootstrap 的下拉列表前面添加图片?

c# - 使用匿名对象和常量列的 LINQ to SQL 中的奇怪行为

javascript - 从 JavaScript 将日期传递给 ADODB.Command 参数

javascript - 改变滚动时html的内容

javascript - 在 Firefox 中阻止 "Would you like to remember this password ?"弹出窗口

javascript - 如何在 chrome 中禁用 iframe 的滚动

css - 需要在 div ie6 和 ie7 中居中一个 ul