• ASP.net对SQL server数据库里取image类型怎么取


    Q: 对SQL   server数据库里取image类型怎么取???  

    A:把aspx的html元素去掉,然后页面中调用以下函数。这个页面返回的就是图片

    private   void  DownloadImage( string  FileID)
            
    {
                
    using  (System.Data.SqlClient.SqlConnection conn  =   new  System.Data.SqlClient.SqlConnection())
                
    {
                    conn.ConnectionString 
    =   " ..... " ;
                    conn.Open();

                    
    using (System.Data.SqlClient.SqlCommand command = conn.CreateCommand())
                    
    {

                        command.CommandText
    = string .Format( " select ImageSize,Image from tablexxx where id='{0}' " , FileID);

                        System.Data.SqlClient.SqlDataReader reader
    = command.ExecuteReader();

                        
    try
                        
    {
                            
    if (reader.Read())
                            
    {
                        
                                
    int  size = reader.GetInt32( 0 );
                                
    byte [] buffer = new   byte [size];

                                reader.GetBytes(
    1 , 0 ,buffer, 0 ,size);

                                
    this .Response.BinaryWrite(buffer);
                            }

                        }

                        
    catch (Exception  ex)
                        
    {
                            
    this .Response.Write(ex.Message);
                        }

                        
    finally
                        
    {
                            reader.Close();
                        }

                    }

                    conn.Close();
                }

            }
  • 相关阅读:
    对象的强、软、弱和虚引用
    spark运行模式之一:Spark的local模式安装部署
    Spark Tungsten in-heap / off-heap 内存管理机制--待整理
    sparkContext之一:sparkContext的初始化分析
    mysql分区表之四:分区表性能
    服务的升级和降级
    怎样编写高质量的 Java 代码
    Java之代理(jdk静态代理,jdk动态代理,cglib动态代理,aop,aspectj)
    Spark Streaming之六:Transformations 普通的转换操作
    Spark Streaming之五:Window窗体相关操作
  • 原文地址:https://www.cnblogs.com/cl1024cl/p/6204991.html
Copyright © 2020-2023  润新知