在Asp.net(C#),如何存储图像数据库(LINQ到SQL)? [英] In Asp.net (c#) ,how to store an image in database(linq to sql)?

查看:99
本文介绍了在Asp.net(C#),如何存储图像数据库(LINQ到SQL)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从客户获得的图像,并将其保存到database..and那么应该得到preVIEW后保存在数据库之前..显示(preVIEW)?
是否有可能在Asp.net用C#...?

i need to get an image from client and displayed(preview) before saving it into database..and then should be saved in database after getting preview..? Is is possible in Asp.net using c#... ?

推荐答案

是的,这是可能的。

如果您使用的是MS SQL Server中,您的表类型图像或VARBINARY声明的字段。 VARBINARY限制取决于您的SQL Server的版本存储字节数,所以形象是要走的路。毕竟,你是存储图像;)

If you are using MS SQL Server, declare a field in your table as type "image" or "varbinary". Varbinary limits the number of bytes stored depending on your version of SQL Server, so "image" is the way to go. After all, you are storing an image ;)

那么你的图像存储为在该领域的字节数组。

Then store your image as a byte array in that field.

在没有看到一些code,它很难给code样品。你直接使用的SqlCommand,LINQ2SQL,实体框架或NHibernate的与您的数据库进行通信?

Without seeing some code, it's hard to give code samples. Are you using SqlCommand directly, Linq2Sql, Entity framework or NHibernate to communicate with your database?

在您的LINQ的对象,你会有一个叫做图像属性格式,如果这就是你命名你的形象/ VARBINARY列。要指定它做到这一点:

On your linq object you will have a propery called Image, if that's what you named your image/varbinary column. To assign it do this:

// assign data
byte[] imageByteArray = ...some byte data...;
myObject.Image = new Binary(imageByteArray);
// save to db
dataContext.YourTable.InsertOnSubmit(myObject); //YourTable is the name of your actual table class
dataContext.SubmitChanges();

其中imageByteArray是一个byte []牵着你的形象。

where imageByteArray is a byte[] holding your image.

二进制目标是围绕一个字节的包装[]。

The Binary object is a wrapper around a byte[].

这篇关于在Asp.net(C#),如何存储图像数据库(LINQ到SQL)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆