if ( int id = null)
        { 
        string sql = "select top 5 * from  context";
        }
        else
        {
            string sql = "select top 5 * from  context where listid=" + id + "";
        }
我的意思是如果id是空值,但不知怎么设置.只会这样写:int id = null 请问怎么写?

解决方案 »

  1.   

     protected string showInfo(int id)
        {
            if ( int id = null)
            { 
            string sql = "select top 5 * from  context";
            }
            else
            {
                string sql = "select top 5 * from  context where listid=" + id + "";
            }
            string tbody = "";
            OleDbDataReader my_reader;
            OleDbCommand my_comm = new OleDbCommand();
           
            my_comm.CommandText= sql;
            my_comm.CommandType = CommandType.Text;
            my_comm.Connection = my_conn;
            my_conn.Open();
            my_reader = my_comm.ExecuteReader();
                       
            }
      

  2.   

     if (  id == null)
            { 
            string sql = "select top 5 * from  context";
            }
            else
            {
                string sql = "select top 5 * from  context where listid=" + id + "";
            }