Google 網路論壇不再支援新的 Usenet 貼文或訂閱項目,但過往內容仍可供查看。

Saving images in table in SQL CE

瀏覽次數:92 次
跳到第一則未讀訊息

James McCutcheon

未讀,
2004年4月8日 清晨5:03:122004/4/8
收件者:
You have to store it as a byte array ...

See Alex's article for more details ...
http://www.opennetcf.org/forums/topic.asp?TOPIC_ID=194

James McCutcheon

"saba" <anon...@discussions.microsoft.com> wrote in message
news:FF17C5DA-4517-4404...@microsoft.com...
> Hi, i am trying to display an image which should be retrieved from a table
in SQL Ce. i don't know how to save/insert an image into a table. Sql Ce
does support image types but i couldn't get any info on how to save it.
Thanks a lot.


Amy Yuan [MS]

未讀,
2004年4月8日 晚上8:04:552004/4/8
收件者:
Hi Saba,

Here's some sameple code you can use. It reads the image col data and store
it in a local bitmap file, make a copy of the file (because of file
sharing) and set image control src to the copy. Might not be the most
elegant solution, but it works.

SqlCeDataReader reader = null;
SqlBinary binary = null;
FileStream f = File.Create ("pet.bmp");

//read current image from DB
if (this.command == null) this.command =
this.connection.CreateCommand();
this.command.CommandText = "SELECT pic from pets where
petname = foo";
reader = command.ExecuteReader();
while (reader.Read())
{
binary = reader.GetSqlBinary(0);
if (binary.IsNull == false)
{
f.Write (binary.Value, 0, binary.Length);
}
}
reader.Close();
f.Flush();
f.Close();

if (null != this.picPet.Image)
this.picPet.Image.Dispose();
File.Copy ("pet.bmp", "petcopy.bmp", true);

//display it in picture control
if (binary.Length > 0)
{
Bitmap photo = new Bitmap("petcopy.bmp");
this.picPet.Image = photo;
}
else
this.picPet.Image = null;

Thanks,
Amy

--------------------
| From: "James McCutcheon" <ja...@nospam.com>
| Newsgroups: microsoft.public.dotnet.framework.compactframework
| References: <FF17C5DA-4517-4404...@microsoft.com>
| Subject: Re: Saving images in table in SQL CE
| Lines: 15
| Organization: j3 Technology
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <kz8dc.108$fP6....@nnrp1.ozemail.com.au>
| Date: Thu, 8 Apr 2004 19:03:12 +1000
| NNTP-Posting-Host: 203.103.159.73
| X-Trace: nnrp1.ozemail.com.au 1081414992 203.103.159.73 (Thu, 08 Apr 2004
19:03:12 EST)
| NNTP-Posting-Date: Thu, 08 Apr 2004 19:03:12 EST
| Path:
cpmsftngxa06.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFTNGP08
.phx.gbl!newsfeed00.sul.t-online.de!t-online.de!news.glorb.com!meganewsserve
rs.com!feeder2.on.meganewsservers.com!newshosting.com!nx02.iad01.newshosting
.com!uunet!dca.uu.net!snewsf0.syd.ops.aspac.uu.net!nnrp1.ozemail.com.au!53ab
2750!not-for-mail
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.compactframework:50519
| X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

0 則新訊息