TextBox1过来的代码:
protected void Button1_Click(object sender, EventArgs e)
    {
        string connString = ConfigurationManager.ConnectionStrings["EDSS"].ConnectionString;
        int ID = Convert.ToInt32(TextBox1.Text );
        SqlConnection connection = new SqlConnection(connString);        string sql = "SELECT  Photo FROM DeviceInfo WHERE ID = "+ @ID ;        SqlCommand command = new SqlCommand(sql, connection);
        command.Parameters.Add(new SqlParameter("@ID", 4));
       
       
        connection.Open();        Stream stream = null;
        object result = command.ExecuteScalar();
stream = new MemoryStream((byte[])result);
            const int buffersize = 1024 * 16;
            byte[] buffer = new byte[buffersize];
            int count = stream.Read(buffer, 0, buffersize);
            while (count > 0)
            {
                Response.OutputStream.Write(buffer, 0, count);
                count = stream.Read(buffer, 0, buffersize);
            }
    }request过来的代码:
protected void Button1_Click(object sender, EventArgs e)
    {
        string connString = ConfigurationManager.ConnectionStrings["EDSS"].ConnectionString;
        int ID= Convert.ToInt32(Request.QueryString["ID"]);
        SqlConnection connection = new SqlConnection(connString);        string sql = "SELECT  Photo FROM DeviceInfo WHERE ID = "+ @ID ;        SqlCommand command = new SqlCommand(sql, connection);
        command.Parameters.Add(new SqlParameter("@ID", 4));
       
       
        connection.Open();        Stream stream = null;
        object result = command.ExecuteScalar();
stream = new MemoryStream((byte[])result);
            const int buffersize = 1024 * 16;
            byte[] buffer = new byte[buffersize];
            int count = stream.Read(buffer, 0, buffersize);
            while (count > 0)
            {
                Response.OutputStream.Write(buffer, 0, count);
                count = stream.Read(buffer, 0, buffersize);
            }
    }奇怪的是并不报错 只是没有显示

解决方案 »

  1.   

    int ID= Convert.ToInt32(Request.QueryString["ID"]);你加上断点看看 ID有值吗?
    最好先判断if(null ==Request.QueryString["ID"])
      

  2.   

    to redwolf_123(雨恨云愁)   
    显示图片      Response.OutputStream.Write(buffer, 0, count);
                   用这个显示to  vzxq(灵感人)
    加上断点了  不是空值  但就是没有自己要的结果
      

  3.   

    string sql = "SELECT  Photo FROM DeviceInfo WHERE ID = '"+ID+"'";