惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Recent Announcements
Recent Announcements
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Last Week in AI
Last Week in AI
Scott Helme
Scott Helme
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
L
LINUX DO - 最新话题
S
Security @ Cisco Blogs
Webroot Blog
Webroot Blog
S
Security Affairs
H
Hacker News: Front Page
TaoSecurity Blog
TaoSecurity Blog
W
WeLiveSecurity
G
GRAHAM CLULEY
T
Tenable Blog
Schneier on Security
Schneier on Security
S
Securelist
Cyberwarzone
Cyberwarzone
P
Privacy International News Feed
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
Schneier on Security
Hacker News - Newest:
Hacker News - Newest: "LLM"
Recent Commits to openclaw:main
Recent Commits to openclaw:main
O
OpenAI News
N
News and Events Feed by Topic
AWS News Blog
AWS News Blog
C
Cisco Blogs
T
Threat Research - Cisco Blogs
S
Secure Thoughts
大猫的无限游戏
大猫的无限游戏
C
Check Point Blog
The GitHub Blog
The GitHub Blog
G
Google Developers Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
美团技术团队
Martin Fowler
Martin Fowler
Microsoft Security Blog
Microsoft Security Blog
L
LangChain Blog
Apple Machine Learning Research
Apple Machine Learning Research
爱范儿
爱范儿
D
DataBreaches.Net
博客园_首页
MyScale Blog
MyScale Blog
博客园 - 叶小钗
博客园 - 三生石上(FineUI控件)
P
Proofpoint News Feed
J
Java Code Geeks
SecWiki News
SecWiki News
P
Palo Alto Networks Blog
Know Your Adversary
Know Your Adversary
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org

博客园 - 老男孩玩编程

PHP双冒号::的用法 php中的反引号 十四条令PHP初学者头疼问题大总结 免费开源微博程序大全——免费开源微博对比解析 JavaScript窗口与提示大全 大型网站,我建议要考虑的问题: 制作精美圆角表格两种方法 关于GridView中自定义分页、单选、多选的简单应用 SQL精华 ASP.NET编程中的十大技巧 SQL SERVER临时表的使用 有效编写软件的75条建议 IT从业人员必看的10个论坛 程序员每天该做的事 动态生成button并关联其onclick事件 在ASP.NET 中实现单点登录 简单的数据连接方法 ASP.NET程序中常用的三十三种代码 SQL语法全集
使用C#从数据库读取图像二进制流的代码
老男孩玩编程 · 2006-12-08 · via 博客园 - 老男孩玩编程

工作需要,要判断一个老的数据库中image存放的数据类型,写了一段代码,放在这里供大家参考。除数据库部分需要大家修改一下以外,其它全部调试正常。里面有意思的是省却了connection的close方法,而用了另一种方式取代,希望大家能注意一下。
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using System.IO;

namespace image
{
 public class Form1 : System.Windows.Forms.Form
 {
  private System.Windows.Forms.Button button1;
  private System.Windows.Forms.ListBox listBox1;
  private System.ComponentModel.Container components = null;

  public Form1()
  {

   InitializeComponent();

  }

  protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if (components != null)
    {
     components.Dispose();
    }
   }
   base.Dispose( disposing );
  }

  #region Windows 窗体设计器生成的代码

  private void InitializeComponent()
  {
   this.button1 = new System.Windows.Forms.Button();
   this.listBox1 = new System.Windows.Forms.ListBox();
   this.SuspendLayout();
 
   this.button1.Location = new System.Drawing.Point(104, 216);
   this.button1.Name = "button1";
   this.button1.TabIndex = 0;
   this.button1.Text = "button1";
   this.button1.Click += new System.EventHandler(this.button1_Click);
  
   this.listBox1.ItemHeight = 12;
   this.listBox1.Location = new System.Drawing.Point(0, 0);
   this.listBox1.Name = "listBox1";
   this.listBox1.Size = new System.Drawing.Size(200, 172);
   this.listBox1.TabIndex = 1;
 
   this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
   this.ClientSize = new System.Drawing.Size(292, 273);
   this.Controls.Add(this.listBox1);
   this.Controls.Add(this.button1);
   this.Name = "Form1";
   this.Text = "Image";
   this.Load += new System.EventHandler(this.Form1_Load);
   this.ResumeLayout(false);

  }
  #endregion

 
  [STAThread]
  static void Main()
  {
   Application.Run(new Form1());
  }

  private void Form1_Load(object sender, System.EventArgs e)
  {
  
  }

  private void button1_Click(object sender, System.EventArgs e)
  {
   string myConnectionString="workstation id=820SERVER;packet size=4096;integrated security=SSPI;data source=820SERVER;persist security info=False;initial catalog=images";
   string mySelectQuery="SELECT * FROM VBADGE";
   CreateMySqlDataReader(mySelectQuery,myConnectionString);
  }

  public void CreateMySqlDataReader(string mySelectQuery,string myConnectionString)
  {
   byte[] tmp;
   SqlConnection myConnection = new SqlConnection(myConnectionString);
   SqlCommand myCommand = new SqlCommand(mySelectQuery, myConnection);
   myConnection.Open();
   SqlDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
   myReader.Read();
   tmp=(byte[])myReader[0];
   FileStream fs = new FileStream("tmp.tmp",FileMode.CreateNew);
   BinaryWriter w = new BinaryWriter(fs);
   w.Write(tmp);
   w.Close();   
   myReader.Close();
  }

 }
}