将图像保存到数据库varbinary(silverlight) [英] Saving image to database as varbinary (silverlight)

查看:150
本文介绍了将图像保存到数据库varbinary(silverlight)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天我一直在试图将图像保存到数据库中,我真的不知道。

Today I have been trying to get an image to save into a database, and I really can't figure it out.

我做了下面的表 Afbeeldingen ):


  • id:int

  • afbeelding1:varbinary(max)

  • id:int
  • afbeelding1:varbinary(max)

用Linq-to-SQL类导入它,为它写了一个WCF服务:

Imported it with a Linq-to-SQL class, wrote a WCF service for it:

    [OperationContract]
    public void setAfbeelding(Afbeelding a)
    {
        dc.Afbeeldings.InsertOnSubmit(a);
        dc.SubmitChanges();
    }

然后在我的xaml页面中,我尝试创建一个 Afbeelding ,但我不能将 Byte [] 作为 varbinary 。我不知道如何做到这一点,我似乎无法找到任何事情。

And then in my xaml page I try to to create an Afbeelding, but I can't put the Byte[] as a varbinary. I don't know how to do this and I can't seem to find anything about it.

OpenFileDialog openFileDialog = new OpenFileDialog();

openFileDialog.Filter = "JPEG files|*.jpg";

if (openFileDialog.ShowDialog() == true)
{
   Stream stream = (Stream)openFileDialog.File.OpenRead();
   Byte[] bytes = new Byte[stream.Length];
   stream.Read(bytes, 0, (int)stream.Length);
   string fileName = openFileDialog.File.Name;

   Afbeelding a = new Afbeelding();
   a.id = 1;
   a.afbeelding1 = new Byte{ Bytes = bytes};
}



我希望有人可以帮助我,因为我真的不能想出来。

I hope somebody can help me because I really can't figure this out.

提前感谢您,
Thomas

Thank you in advance, Thomas

编辑:解决了这个问题, 。当我按下按钮,我得到一个错误

Having solved this problem, what happens now when I press the button as I get an error.

System.ServiceModel.FaultException: The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter :a. The InnerException message was 'There was an error deserializing the object of type OndernemersAward.Web.Afbeelding. The maximum array length quota (16384) has been exceeded while reading XML data. This quota may be increased by changing the MaxArrayLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader.'.  Please see InnerException for more details.
   at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
   at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
   at System.ServiceModel.ClientBase`1.ChannelBase`1.EndInvoke(String methodName, Object[] args, IAsyncResult result)
   at OndernemersAward.EditAfbeeldingServiceReference.EditAfbeeldingServiceClient.EditAfbeeldingServiceClientChannel.EndsetAfbeelding(IAsyncResult result)
   at OndernemersAward.EditAfbeeldingServiceReference.EditAfbeeldingServiceClient.OndernemersAward.EditAfbeeldingServiceReference.EditAfbeeldingService.EndsetAfbeelding(IAsyncResult result)
   at OndernemersAward.EditAfbeeldingServiceReference.EditAfbeeldingServiceClient.OnEndsetAfbeelding(IAsyncResult result)
   at System.ServiceModel.ClientBase`1.OnAsyncCallCompleted(IAsyncResult result)


推荐答案

http://msdn.microsoft.com/en-us/library/bb359955.aspx =nofollow>二进制对象。

You need to construct a Binary object.

a.afbeelding1 = new Binary( bytes );

这篇关于将图像保存到数据库varbinary(silverlight)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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