Insertion d'un byte[] dans une bdd mssql 2005
Bonjour,
j'ai un petit soucis lors de l'insertion d'un tableau de byte dans SQL serveur
j'ai une procédure stocké
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
USE [AjaxIntranetHeig]
GO
IF EXISTS
(SELECT name FROM sysobjects WHERE name = 'AddPhototoStudent' AND type = 'P')
DROP PROCEDURE [AddPhototoStudent]
GO
/****** Objet : StoredProcedure [dbo].[AddPhototoStudent] Create date : 03/01/2007 19:56:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[AddPhototoStudent]
@Name NVARCHAR(256)
,@Description NVARCHAR(256)
,@File BINARY
,@Tag NVARCHAR(256)
,@FkIdUSer UNIQUEIDENTIFIER
AS
BEGIN
DECLARE @Id UNIQUEIDENTIFIER;
SET @Id = NEWID();
INSERT INTO [AjaxIntranetHeig].[dbo].[Photo]
([Id]
,[Name]
,[Description]
,[File]
,[Tag]
,[FkIdUSer])
VALUES
(@Id
,@Name
,@Description
,@File
,@Tag
,@FkIdUSer)
SELECT @Id as id;
END |
J'ai un appel de cette procédure
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
/// <summary>
/// Create a new picture in database
/// </summary>
/// <param name="name">Photo's name</param>
/// <param name="description">Photo's description</param>
/// <param name="image">Image to add(in Byte[])</param>
/// <param name="tag">image tag for search</param>
/// <param name="idStudent">Id of picture's owner</param>
public Guid AddPhototoStudent(string name, string description, byte[] image, string tag, Guid idStudent)
{
SqlCommand myCommand = new SqlCommand("AddPhototoStudent", Connexion);
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.Add("@Name", SqlDbType.NVarChar, 256);
myCommand.Parameters.Add("@Description", SqlDbType.NVarChar,256);
myCommand.Parameters.Add("@File", SqlDbType.Binary, image.Length);
myCommand.Parameters.Add("@Tag", SqlDbType.NVarChar, 256);
myCommand.Parameters.Add("@FkIdUSer", SqlDbType.UniqueIdentifier);
myCommand.Parameters["@Name"].Value = name;
myCommand.Parameters["@Description"].Value = description;
myCommand.Parameters["@File"].Value = image;
myCommand.Parameters["@Tag"].Value = tag;
myCommand.Parameters["@FkIdUSer"].Value = idStudent;
object result = ExecProcecure(myCommand);
if (result == null)
throw new Exception(Error);
else
return new Guid(result.ToString());
} |
A ce moment la mon byte[] (byte[] image) est égal à :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
| >? image
{Dimensions:[85577]}
[0]: 71
[1]: 73
[2]: 70
[3]: 56
[4]: 57
[5]: 97
[6]: 88
[7]: 2
[8]: 194
[9]: 1
[10]: 247
[11]: 0
[12]: 0
[13]: 0
[14]: 0
[15]: 0
[16]: 128
[17]: 0
[18]: 0
[19]: 0
[20]: 128
[21]: 0
[22]: 128
[23]: 128
[24]: 0
[25]: 0
[26]: 0
[27]: 128
[28]: 128
[29]: 0
[30]: 128
[31]: 0
[32]: 128
[33]: 128
[34]: 128
[35]: 128
[36]: 128
[37]: 192
[38]: 192
[39]: 192
[40]: 255
[41]: 0
[42]: 0
[43]: 0
[44]: 255
[45]: 0
[46]: 255
[47]: 255
[48]: 0
[49]: 0
[50]: 0
[51]: 255
[52]: 255
[53]: 0
[54]: 255
[55]: 0
[56]: 255
[57]: 255
[58]: 255
[59]: 255
[60]: 255
[61]: 0
[62]: 0
[63]: 0
[64]: 0
[65]: 0
[66]: 0
[67]: 0
[68]: 0
[69]: 0
[70]: 0
[71]: 0
[72]: 0
[73]: 0
[74]: 0
[75]: 0
[76]: 0
[77]: 0
[78]: 0
[79]: 0
[80]: 0
[81]: 0
[82]: 0
[83]: 0
[84]: 0
[85]: 0
[86]: 0
[87]: 0
[88]: 0
[89]: 0
[90]: 0
[91]: 0
[92]: 0
[93]: 0
[94]: 0
[95]: 0
[96]: 0
[97]: 0
[98]: 0
[99]: 0
< Plus... (Les 100 premiers des 85577 éléments ont été affichés.) > |
Hors lorsque que je recupere via un select ce meme tableau (j'ai fais un truc tout simple a l'arrache, pensant que mes problemes venaient de mon code)
Code:
1 2 3 4 5
|
SqlCommand cmd = new SqlCommand("select [file] from photo where id = 'DF426DA8-FA72-4A23-8CDC-0C697A117C2B'",Connexion);
Connexion.Open();
byte[] toto = (byte[])cmd.ExecuteScalar();
Connexion.Close(); |
j'obtiens
>? cmd.ExecuteScalar()
{Dimensions:[1]}
[0]: 71
En base de donné sur un select j'ai '0x47'
Je pense donc que c'est mon insert qui merdouille mais je vois pas pourquoi.
Toute aide sera fortement appréciée, d'avance merci :)