tipo net mostrar insertar imagenes imagen guardar desde datos dato como cargar asp agregar database silverlight image linq-to-sql varbinary

database - insertar - mostrar imagen desde base de datos en asp net c#



Guardar imagen en la base de datos como varbinary(silverlight) (1)

Hoy he intentado obtener una imagen para guardar en una base de datos, y realmente no puedo resolverlo.

He hecho la siguiente tabla ( Afbeeldingen ):

  • id:int
  • afbeelding1:varbinary(max)

Lo importé con una clase Linq-to-SQL y le escribí un servicio WCF:

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

Y luego en mi página xaml trato de crear un Afbeelding , pero no puedo poner el Byte[] como varbinary . No sé cómo hacer esto y parece que no puedo encontrar nada al respecto.

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}; }

Espero que alguien pueda ayudarme porque realmente no puedo resolver esto.

Gracias de antemano, Thomas

Editar: Habiendo resuelto este problema, ¿qué pasa ahora cuando presiono el botón cuando obtengo un 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)


Necesitas construir un objeto Binario .

a.afbeelding1 = new Binary( bytes );