我有一个字符串喜欢5.5kg或7.90gram我想得到5.5或7.90作为十进制值.如何在C#中获得这样的结果,还有一件事我的字符串将始终以十进制开头.
这是我的代码,只要遇到除小数之外的任何内容,就会抛出错误.
string weight = attributeValue;
if (!string.IsNullOrEmpty(weight))
{
product.Weight = Convert.ToDecimal(attributeValue);
}
else
{
product.Weight = 0.00m;
}
Run Code Online (Sandbox Code Playgroud) 执行此查询时获取错误,因为列文本也可能包含带单引号的文本.如何使用此查询没有任何错误我的代码是
public bool updateCMStable(int id, string columnName, string columnText)
{
try
{
string sql = "UPDATE CMStable SET " + columnName +
"='" + columnText + "' WHERE cmsID=" + id;
int i = SqlHelper.ExecuteNonQuery(Connection.ConnectionString,
CommandType.Text,
sql);
if (i > 0)
{
return true;
}
else
{
return false;
}
}
catch (Exception ee)
{
throw ee;
}
}
Run Code Online (Sandbox Code Playgroud) 我在db中有一个存储html的字段,我想在用户端呈现该html.但我无法这样做.当我试图把html放在div标签或段落标签,然后我得到简单的HTML文本.这是我试过的代码
<%: HttpContext.Current.Server.HtmlDecode(Model.HomePageText) %>
Run Code Online (Sandbox Code Playgroud)
我使用这个得到以下结果(HTML显示为文本)
<p> </p> <p style="color: rgb(88, 100, 109); font-family: 'PT Sans', sans-serif; font-size: 13px; line-height: 16px; background-position: -1px -350px; "> Enter custom CSS code into the box below to further customize your mobile site.</p>
Run Code Online (Sandbox Code Playgroud)