日期:2014-05-18  浏览次数:20394 次

SQL 语句动态写法 ?在线等
SQL 语句能这样写吗 我要查询的是动态的 可变的

C# code


SqlConnection con = new SqlConnection("server=localhost;database=7daydian;uid=sa;pwd=1234");


        string dia = "dianliang";

        string sql = "select '"+dia+"' from tongji order by shijian";

        SqlCommand com = new SqlCommand(sql, con);





我执行了下 没有结果

应该怎样写啊  
在线等 急!

------解决方案--------------------
dia是字段名?
 string sql = "select " + dia + " from tongji order by shijian";
这样写
------解决方案--------------------
C# code

 string sql = 'select "+dia+" from tongji order by shijian';

------解决方案--------------------
探讨

引用:
dia是字段名?
string sql = "select " + dia + " from tongji order by shijian";
这样写

C# code

string sql = "select distinct [name] as 板块名称 ,[" + mon + "]as [周一]
,[" + thur + "]as [周2]
,[……

------解决方案--------------------
探讨

dia是字段名?
string sql = "select " + dia + " from tongji order by shijian";
这样写