我有下面的C#代码:C#String Concationation问题为什么不在这里工作?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace StringTest
{
class Program
{
static void Main(string[] args)
{
String strSQLCode;
strSQLCode = " select rank() over (order by percentagecorrect desc, totalmilliseconds asc) as rank, * "
+= " from view_dg_game_details gd (nolock) "
+= " where gd.gametypeid = {0} "
+= " and gd.numberofrounds = {1} "
+= " and gd.gamevalues = '{2}' ";
}
}
}
出于某种原因,我得到一个错误“赋值的左边必须是一个变量,属性或索引”。
我看不出错误在告诉我什么。我已经评论了有问题的路线,但是错误只是上移了一条线。
我能得到的字符串concation使用这种方法的工作:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace StringTest
{
class Program
{
static void Main(string[] args)
{
String strSQLCode;
strSQLCode = " select rank() over (order by percentagecorrect desc, totalmilliseconds asc) as rank, * ";
strSQLCode = strSQLCode + " from view_dg_game_details gd (nolock) ";
strSQLCode = strSQLCode + " where gd.gametypeid = {0} ";
strSQLCode = strSQLCode + " and gd.numberofrounds = {1} ";
strSQLCode = strSQLCode + " and gd.gamevalues = '{2}' ";
}
}
}
有人能向我解释一下这个错误是什么?
感谢
肯
您有SQL注入漏洞。 – SLaks 2012-02-14 18:53:13
字符串连接效率较低,在这里最好使用'@'字符串。 – McKay 2012-02-14 18:56:37
@McKay:我想象编译器在编译时将它们结合起来。 – 2012-02-14 19:07:27