打印本文 打印本文 关闭窗口 关闭窗口
【翻译】保存图片到SQL 2000 Server数据库
作者:武汉SEO闵涛  文章来源:敏韬网  点击数5703  更新时间:2007/11/14 13:00:11  文章录入:mintao  责任编辑:mintao
页面上?

这里,我使用Web页面来显示图片,而没有用其他任何控件。下面的代码是用来显示数据库中的图片。

private void Page_Load(object sender, System.EventArgs e)

{

    MemoryStream stream = new MemoryStream ();

    SqlConnection connection = new 

      SqlConnection (@"server=INDIA\INDIA;database=iSense;uid=sa;pwd=india");

    try

    {

        connection.Open ();

        SqlCommand command = new 

          SqlCommand ("select Picture from Image", connection);

        byte[] image = (byte[]) command.ExecuteScalar ();   

        stream.Write (image, 0, image.Length);

        Bitmap bitmap = new Bitmap (stream);

        Response.ContentType = "image/gif";

        bitmap.Save (Response.OutputStream, ImageFormat.Gif);

    } 

    finally

    {

        connection.Close ();

上一页  [1] [2] [3] [4] [5]  下一页

打印本文 打印本文 关闭窗口 关闭窗口