当前位置:首页 » 多媒体相关

.NET 连接SQL SERVER2000数据库时如何操作IMAGE字段?


问题1:我的数据库中有一个字段为image   字段  
  我想在.net   中把该字段的数据显示到datagrid中或显示到picture控件中,  
  问题2:如果我在窗口中更改了一个图片该如何上传到数据库中?  
   
  哪位有关于.net   连接   sql   server   读取,存放图片的例子.谢谢

推荐阅读

  • Java编程图像处理技巧 [详细内容]
  • 日本3G业务改变青年生活方式 [详细内容]
  • 破解WiMAX物理层测试瓶颈 [详细内容]
  • JSP显示内容缓存技巧 [详细内容]
  • 轻松实现简体输入,不是国笔,而是“无敌快手” [详细内容]
  • 分析:杀手级应用是移动运营商3G发展之关键 [详细内容]
  • Win XP的20个特殊技巧 [详细内容]
  • 网友回答:
    网友:mingyuebin

    读取到picturebox  
      dim   pic()   as   byte=ctype(mydataset.tables(0).rows(0)("pic"),byte)  
      dim   ms   as   new   memorystream(pic)  
      picturebox1.image=image.fromstream(ms)  
     

    网友:yewei4u

    string   id   =   (string)   context.request["id"];  
       
                      if   (id   !=   null)   {  
                              memorystream   stream   =   new   memorystream   ();  
                              sqlconnection   connection   =   new   sqlconnection  
                                      ("server=localhost;database=northwind;uid=sa;pwd=");  
                              bitmap   bitmap   =   null;  
                              image   image   =   null;  
       
                              try   {    
                                      connection.open   ();  
                                      sqlcommand   cmd   =   new   sqlcommand  
                                              ("select   photo   from   employees   where   employeeid="   +  
                                              id   +   "",   connection);  
                                      byte[]   blob   =   (byte[])   cmd.executescalar   ();    
       
                                      stream.write   (blob,   78,   blob.length   -   78);  
                                      bitmap   =   new   bitmap   (stream);  
       
                                      //   shrink   the   image,   but   maintain   its   aspect   ratio  
                                      int   width   =   48;  
                                      int   height   =   (int)   (width   *    
                                              ((double)   bitmap.height   /   (double)   bitmap.width));  
                                      image   =   bitmap.getthumbnailimage   (width,   height,   null,  
                                              intptr.zero);  
       
                                      context.response.contenttype   =   "image/jpeg";  
                                      image.save   (context.response.outputstream,   imageformat.jpeg);    
                              }  
                              finally   {    
                                      if   (image   !=   null)  
                                              image.dispose   ();  
                                      if   (bitmap   !=   null)  
                                              bitmap.dispose   ();  
                                      stream.close   ();  
                                      connection.close   ();  
                              }

    .

    讨论区

    Login