-1

cmd.Parameters.AddWithValue("@id", new system.Guid (imageid));

这需要什么使用系统参考?

这是处理程序:

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;
    }
}
}
4

1 回答 1

1

可能是笔误。将 System 命名空间的第一个字母大写。

new System.Guid (imageid)
于 2011-01-08T07:48:04.823 回答