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

推荐订阅源

L
LangChain Blog
C
Check Point Blog
博客园 - Franky
V
Visual Studio Blog
云风的 BLOG
云风的 BLOG
aimingoo的专栏
aimingoo的专栏
Microsoft Security Blog
Microsoft Security Blog
V2EX - 技术
V2EX - 技术
AI
AI
Hacker News - Newest:
Hacker News - Newest: "LLM"
Jina AI
Jina AI
S
Security @ Cisco Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
H
Hacker News: Front Page
H
Hackread – Cybersecurity News, Data Breaches, AI and More
O
OpenAI News
Attack and Defense Labs
Attack and Defense Labs
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
爱范儿
爱范儿
H
Heimdal Security Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
G
Google Developers Blog
G
GRAHAM CLULEY
V
V2EX
The Register - Security
The Register - Security
人人都是产品经理
人人都是产品经理
B
Blog RSS Feed
Schneier on Security
Schneier on Security
M
MIT News - Artificial intelligence
Stack Overflow Blog
Stack Overflow Blog
Help Net Security
Help Net Security
大猫的无限游戏
大猫的无限游戏
C
CERT Recently Published Vulnerability Notes
The GitHub Blog
The GitHub Blog
V
Vulnerabilities – Threatpost
The Last Watchdog
The Last Watchdog
J
Java Code Geeks
S
Secure Thoughts
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
量子位
NISL@THU
NISL@THU
K
Kaspersky official blog
Engineering at Meta
Engineering at Meta
T
Threatpost
Recent Commits to openclaw:main
Recent Commits to openclaw:main
宝玉的分享
宝玉的分享
Security Latest
Security Latest
T
The Exploit Database - CXSecurity.com
博客园_首页
A
Arctic Wolf

博客园 - joyous jeny

Log4Net advanced pattern tips SQLServer的TDE加密 Forrest Gump frontend learning site JDK JRE区别 用户中心 - 博客园 用户中心 - 博客园 用户中心 - 博客园 转:jQuery设计思想 marked ASP.NET 页面对象模型 3种方法从Html中取文本 WebResource - joyous jeny - 博客园 让DropDownlist显示ToolTip(两部分) - joyous jeny - 博客园 Tech tips(回发、显示名称、DataView过滤前10条记录) - joyous jeny ASP脚本里加事务 Make a mark of Gates .net 20 callback example 导出Datagrid里所有数据到excel - joyous jeny - 博客园 比较经典的日期判断 - joyous jeny - 博客园
图片的存取
joyous jeny · 2011-03-24 · via 博客园 - joyous jeny

 //存图片到DB
    private void button1_Click(object sender, EventArgs e)
    {
        Stream ms;
        byte[] picbyte;
        OpenFileDialog ofdSelectPic = new OpenFileDialog();
        ofdSelectPic.ShowDialog();
        string f = ofdSelectPic.FileName;

        ms = ofdSelectPic.OpenFile();
        picbyte = new byte[ms.Length];
        ms.Position = 0;
        ms.Read(picbyte, 0, Convert.ToInt32(ms.Length));

        SqlConnection conn = new SqlConnection("server=.;uid=sa;pwd=;database=s");
        conn.Open();
        string sqlstring = "insert into ttt(image) values(@img)";
        SqlCommand cmd = new SqlCommand(sqlstring, conn);
        cmd.Parameters.Add("@img", SqlDbType.Image, picbyte.Length).Value = picbyte;

        cmd.ExecuteNonQuery();
        conn.Close();
    }
    //由数据取图片

    private void button2_Click(object sender, EventArgs e)
    {
        SqlConnection conn = new SqlConnection("server=.;uid=sa;pwd=;database=s");
        conn.Open();
        string strSql = "select image from ttt ";
        SqlCommand cmd = new SqlCommand(strSql, conn);
        SqlDataReader sdr = cmd.ExecuteReader();
        sdr.Read();
        MemoryStream ms = new MemoryStream((byte[])sdr[0]);
        Image image = Image.FromStream(ms);
        sdr.Close();
        conn.Close();
        pictureBox1.Image = image;
    }