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

推荐订阅源

V
Vulnerabilities – Threatpost
U
Unit 42
F
Fortinet All Blogs
aimingoo的专栏
aimingoo的专栏
P
Proofpoint News Feed
F
Full Disclosure
月光博客
月光博客
Engineering at Meta
Engineering at Meta
博客园_首页
The Register - Security
The Register - Security
G
Google Developers Blog
The Cloudflare Blog
博客园 - Franky
K
Kaspersky official blog
A
Arctic Wolf
Scott Helme
Scott Helme
C
Cisco Blogs
Hugging Face - Blog
Hugging Face - Blog
C
Check Point Blog
NISL@THU
NISL@THU
AI
AI
D
DataBreaches.Net
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Stack Overflow Blog
Stack Overflow Blog
Project Zero
Project Zero
The GitHub Blog
The GitHub Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
量子位
Vercel News
Vercel News
T
Tor Project blog
P
Privacy International News Feed
D
Docker
I
Intezer
L
LangChain Blog
P
Proofpoint News Feed
Security Latest
Security Latest
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threatpost
博客园 - 聂微东
AWS News Blog
AWS News Blog
Martin Fowler
Martin Fowler
P
Privacy & Cybersecurity Law Blog
V
V2EX
Last Week in AI
Last Week in AI
C
Cybersecurity and Infrastructure Security Agency CISA
The Hacker News
The Hacker News
T
Tenable Blog
Blog — PlanetScale
Blog — PlanetScale
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tailwind CSS Blog

博客园 - 冰封王座(.net)博客

实现qq的自动登录 - 冰封王座(.net)博客 - 博客园 创建带签名的cab包的完整流程 在C#中使用 makecert 创建自签名的证书 对比 javascript url编码 有关 java 与 C#细节不同 - 冰封王座(.net)博客 mysql常用命令 使用 DotnetOpenMail发送带附件的邮件 - 冰封王座(.net)博客 - 博客园 今天你处理异常了么? 防止SQL注入攻击 在DataGrid中进行值映射 - 冰封王座(.net)博客 - 博客园 UML视图使用 想要做个开源 大家谁有创意啊? 程序员每天该做的事 Google SiteMap的作用及协议格式详解[转摘] 取得客户端MAC Java学习之路:不走弯路,就是捷径 开发人员必备网站 css 外层保持固定高度的情况下 能随内层高度自适应变化 新的学习计划(10/8--10/15)
Acess 存储与显示图片
冰封王座(.net)博客 · 2006-10-15 · via 博客园 - 冰封王座(.net)博客

在Acess 存储图片:
   1.在Access中存储图片的字段为"Ole 对象"
   2.将上传的文件存到 字节数组 中.
   3.然后将该数据存到数据库里就行了.

 1 private void UpLoadFile()
 2    {
 3        //get the file
 4        Stream uploadStream = FileUpload1.PostedFile.InputStream;
 5        int fileLengh = FileUpload1.PostedFile.ContentLength;
 6        byte[] filedata = new byte[fileLengh];
 7        uploadStream.Read(filedata, 0, fileLengh);
 8        string filename = FileUpload1.PostedFile.FileName;
 9        string filetype = FileUpload1.PostedFile.ContentType;
10
11        //
12        OleDbConnection conn = new OleDbConnection(CONSTRING);
13        OleDbCommand comm = new OleDbCommand();
14        comm.Connection = conn;
15        
16        //comm.CommandText = "insert into person (name,photo) values("+TName.Text.Trim()+","++")";
17        //
18        comm.CommandText = "insert into person (name,photo) values (@name,@photo)";
19        //
20        OleDbParameter name = new OleDbParameter("@name",OleDbType.VarChar,50);
21        name.Value = "aaa";
22        comm.Parameters.Add(name);
23        OleDbParameter photo = new OleDbParameter("@photo", OleDbType.Binary);
24        photo.Value = filedata;
25        comm.Parameters.Add(photo);
26        //
27        conn.Open();
28        comm.ExecuteReader();
29        conn.Close();
30
31    }



在Access中显示图片:
        在ASP.NET2.0中显示数据库中的图片,可以利用HttpHandler(.ashx)页面动态显示图片.
        然后在GridView等控件的自定义模版中安置一个Image控件,并设置Image控件的ImageUrl属性为类似 XXX.ashx?photoId=1 即可显示图片
        实例代码:

 1using System;
 2using System.Web;
 3using System.Data.OleDb;
 4using System.IO;
 5
 6public class Handler : IHttpHandler {
 7    
 8    public void ProcessRequest (HttpContext context) {
 9        context.Response.ContentType = "image/jpeg";
10        context.Response.Cache.SetCacheability(HttpCacheability.Public);
11        context.Response.BufferOutput = false;
12        int personId = -1;
13        Stream stream = null;
14        if (context.Request.QueryString["PersonID"!= null && context.Request.QueryString["PhotoID"!= "")
15        {
16        personId = Convert.ToInt32(context.Request.QueryString["PersonID"]);
17        stream = GetPhoto(personId);
18        }

19        const int buffersize = 1024 * 16;
20        byte[] buffer = new byte[buffersize];
21        int count = stream.Read(buffer, 0, buffersize);
22        while (count > 0)
23        {
24            context.Response.OutputStream.Write(buffer, 0, count);
25            count = stream.Read(buffer, 0, buffersize);
26         }

27    }

28    
29    public Stream GetPhoto(int personId)
30    {
31        OleDbConnection myConnection = new OleDbConnection();
32        myConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\\db1.mdb";
33        OleDbCommand myCommand = new OleDbCommand("SELECT Photo FROM Person WHERE Id=@Id",myConnection);
34        myCommand.Parameters.Add(new OleDbParameter("@Id", personId));
35        myConnection.Open();
36        object result = myCommand.ExecuteScalar();
37
38        try 
39        {
40            return new MemoryStream((byte[])result);
41        }

42        catch (ArgumentNullException e)
43        {
44            return null;
45        }

46        finally{
47            myConnection.Close();
48        }

49    }

50
51 
52    public bool IsReusable {
53        get {
54            return false;
55        }

56    }

57
58}

最后在控件的模板中可以这样帮定,实例代码:

1<asp:GridView ID="GridView1" runat="server" AllowPaging="True" OnPageIndexChanged="GridView1_PageIndexChanged" OnPageIndexChanging="GridView1_PageIndexChanging" PageSize="1">
2            <Columns>
3                <asp:TemplateField HeaderText="Photo">
4                    <ItemTemplate>
5                        <asp:Image ID="Image1" runat="server" ImageUrl='<%# "Handler.ashx?PersonId=" + Eval("Id") %>' Width="200px" />
6                    </ItemTemplate>
7                </asp:TemplateField>
8            </Columns>
9        </asp:GridView>