比如我有个变量
string a ="90";
我想要查询我biao表中o列 值等于变量a里的值的内容
sql * from biao where  o=[变量a]

解决方案 »

  1.   

    string a="90";
    sql="select * from biao where o='"+a+"'"
      

  2.   

    string.format("select * from table where 1=1 {0}{1}","and a='90'","and b=81");
      

  3.   

    写个带参数的方法(条件就where 的条件)
    String sql="sql * from biao where o="+变量;
      

  4.   

    可以用parameter方式,不建议用字符串拼接,防止注入攻击! StringBuilder strSql=new StringBuilder();
    strSql.Append("select count(1) from BanzouChart");
    strSql.Append(" where ID=@ID ");
    SqlParameter[] parameters = {
    new SqlParameter("@ID", SqlDbType.Int,4)};
    parameters[0].Value = ID;
      

  5.   

    string a ="90";
    sql="select  * from biao where o='"+a+"'";
    或string.format
    sqlparameter
    select  * from biao where o=@a
      

  6.   

    如果楼主仅仅是实现说的那个功能的话
    就这样的回答了。附上早几天有人问的一个类似问题的解决方案:
    http://topic.csdn.net/u/20101222/09/2a65fc74-9f30-4da1-8d6b-6d3353c8ad6b.html
      

  7.   


      //字符串型:
                string a = "90";
                string sql = "select * from biao where o='" + a + "'";            //数字型
                int i = 10;
                sql = "select * from biao where o=" + i + "";
      

  8.   

    如果变量中带‘ 之类的符号可以在前面加上@string sql=@“select * from table where o=’yo’yo‘”;