2011-01-08 71 views
-1

cmd.Parameters.AddWithValue("@id", new system.Guid (imageid));public class ImageHandler:IHttpHandler

什麼使用系統參考將這需要?

這裏是處理:

using System; 
using System.Collections.Specialized; 
using System.Web; 
using System.Web.Configuration; 
using System.Web.Security; 
using System.Globalization; 
using System.Configuration; 
using System.Data.SqlClient; 
using System.Data; 
using System.IO; 
using System.Web.Profile; 
using System.Drawing; 

public class ImageHandler : IHttpHandler { 

public void ProcessRequest(HttpContext context) 
{ 
    string imageid; 
    if (context.Request.QueryString["id"] != null) 
     imageid = (context.Request.QueryString["id"]); 
    else 
     throw new ArgumentException("No parameter specified"); 

    context.Response.ContentType = "image/jpeg"; 
    Stream strm = ShowProfileImage(imageid.ToString()); 
    byte[] buffer = new byte[8192]; 
    int byteSeq = strm.Read(buffer, 0, 8192); 

    while (byteSeq > 0) 
    { 
     context.Response.OutputStream.Write(buffer, 0, byteSeq); 
     byteSeq = strm.Read(buffer, 0, 8192); 
    } 
    //context.Response.BinaryWrite(buffer); 
} 

public Stream ShowProfileImage(String imageid) 
{ 
    string conn = ConfigurationManager.ConnectionStrings["MyConnectionString1"].ConnectionString; 
    SqlConnection connection = new SqlConnection(conn); 
    string sql = "SELECT image FROM Profile WHERE UserId = @id"; 
    SqlCommand cmd = new SqlCommand(sql, connection); 
    cmd.CommandType = CommandType.Text; 
    cmd.Parameters.AddWithValue("@id", new system.Guid (imageid));//Failing Here!!!! 
    connection.Open(); 
    object img = cmd.ExecuteScalar(); 
    try 
    { 
     return new MemoryStream((byte[])img); 
    } 
    catch 
    { 
     return null; 
    } 
    finally 
    { 
     connection.Close(); 
    } 
} 

public bool IsReusable 
{ 
    get 
    { 
     return false; 
    } 
} 
} 
+1

呃......呃......呃......什麼!? – 2011-01-08 07:35:45

回答

1

也許錯字。大寫系統命名空間的第一個字母。

new System.Guid (imageid)