zoukankan      html  css  js  c++  java
  • 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();
                }

            }
  • 相关阅读:
    TrieTree的学习
    单调队列(monotonic queue)列与单调栈的学习
    507. Perfect Number
    157. Read N Characters Given Read4
    nsexec
    nsenter
    setjmp
    runc 测试
    cgo setns + libcontainer nsexec
    前端 导出为Excel 数据源为table表格 并且table中含有图片
  • 原文地址:https://www.cnblogs.com/cl1024cl/p/6204991.html
Copyright © 2011-2022 走看看