selectuser  1010 1
selectinfo  1111
selectuser  1011 0 要根据下面字符串替换
select * from User where user = {0} and status = {1}
此句对应 selectuser 这条命令即替换成
select * from User where user = 1010 and status = 1
select * from User where user = 1011 and status = 0select * from UserInfo where user = {0} 
此句对应selectinfo 这条命令
即select * from UserInfo where user = 1111
不知道大家有什么好办法没,上面是一个字符串

解决方案 »

  1.   

    string s=string.Format("select * from User where user = {0} and status = {1}",1010,1);
      

  2.   

    用string.format方法就可以了  
    楼主自己去msdn上查下用法吧 
      

  3.   

    我的意思是给你下面这个字符串
    selectuser  1010 1 
    selectinfo  1111 
    selectuser  1011 0 只能根据这个字符串,来替换下面的命令,那些数字是动态的,这里只是举个例子select * from User where user = 1010 and status = 1 
    select * from User where user = 1011 and status = 0 select * from UserInfo where user = 1111 
      

  4.   


    string.Format("select * from User where user = {0} and status = {1}",1010,1);

    val0 = 1010, val1 =1 ;//变量,可 FOR 循环赋值!
    string sql="select * from User where user = "+ val0 +" and status = "+ val1 +"";1010,1的 值 放到 数组 或 表当中!进行 循环! 就能查到你需要所有记录!
    string sql="";foreach(DataRow dr in DT.Rows) //   或 数组
    {
    sql += "select * from User where user = "+ dr[0]+" and status = "+ dr[1]+" union ";
    }sql.Substring(0, sql.Length -6)
      

  5.   


    return 
    (select * from User where user = {0} and status = {1})
    .Replace("{0}", 传进来的值1)
    .Replace("{1}", 传进来的值2);
    方法很多, 此为一例.
      

  6.   


    return
    ("select*from Userwhere user= {0} and status= {1}")
    .Replace("{0}", 传进来的值1)
    .Replace("{1}", 传进来的值2);
    我汗.
      

  7.   

    string sql = "";
                    string strTemp = "selectuser 1010 1";
                    string[] s = strTemp.split(' ');
                   
                        if(s[0].ToLower() == "selectuser")
                        {
                            sql = "select * from User ";
                        }
                        else if(s[0].ToLower() == "selectuser")
                        {
                            sql = "select * from UserInfo  ";
                        }
                        else
                        {
                            return sql;
                        }
                    string strWhere ="";
                    if(s[1].Length>0)
                        strWhere = " and user = " + s[1];
                    if(s[2].Length>0)
                        strWhere += " and status = " + s[2];
                    strWhere = " where " + strWhere.Substring(4);
                    sql = sql +strWhere;
                    return sql;