C# 使用cookie名称更新表mysql create
我在c#中的项目创建一个临时表,用于单用户身份验证,并记住用户名和cookie 现在我需要用cookie名称更新这个临时表mysql create,但我有一个错误:C# 使用cookie名称更新表mysql create,c#,mysql,cookies,C#,Mysql,Cookies,我在c#中的项目创建一个临时表,用于单用户身份验证,并记住用户名和cookie 现在我需要用cookie名称更新这个临时表mysql create,但我有一个错误: Compiler Error Message: CS1010: Newline in constant 怎么了 下面是我的代码 private void UpdateProduct(string productID) { string sql = String.Format(@"Update `tbl_" + Reques
Compiler Error Message: CS1010: Newline in constant
怎么了
下面是我的代码
private void UpdateProduct(string productID)
{
string sql = String.Format(@"Update `tbl_" + Request.Cookies["userName"].Value + "`
set Product = 1
where ID = {0}",
productID);
using (OdbcConnection cn =
new OdbcConnection(ConfigurationManager.ConnectionStrings["MySQL"].ConnectionString))
{
cn.Open();
using (OdbcCommand cmd = new OdbcCommand(sql, cn))
{
cmd.ExecuteNonQuery();
}
}
}
你的
部分仍然需要是逐字字符串文字,因为它是多行字符串。像这样改变它
string sql = String.Format(@"Update `tbl_" + Request.Cookies["userName"].Value + @"`
set Product = 1
where ID = {0}",
productID);
我认为您不需要在表名中使用严重的重音字符,因为它不是关键字或其他东西
顺便说一下,由于您将表作为输入,因此我强烈建议您在将其放入sql或创建白名单之前进行一次强验证。但是,您应该始终使用。这种类型的字符串连接对攻击是开放的
string sql = String.Format(@"Update `tbl_" + Request.Cookies["userName"].Value + @"`
set Product = 1
where ID = {0}",
productID);