Sì, si sarà in grado di ottenere indietro il vostro array multi-dimensionale inalterata.
Come si può fare? Utilizzo di un campo Varbinary (max) in Sql Server e salvataggio in esso della matrice di byte multidimensionale serializzata. Al fine di riavere il tuo array, ovviamente, devi deserializzare ciò che hai archiviato nel database.
Ecco un esempio di come farlo:
public void TestSO()
{
using (SqlConnection conexion = new SqlConnection())
{
using (SqlCommand command = new SqlCommand())
{
//This is the original multidimensional byte array
byte[,] byteArray = new byte[2, 2] {{1, 0}, {0,1}};
ConnectionStringSettings conString = ConfigurationManager.ConnectionStrings["ConnectionString"];
conexion.ConnectionString = conString.ConnectionString;
conexion.Open();
command.Connection = conexion;
command.CommandType = CommandType.Text;
command.CommandText = "UPDATE Table SET VarBinaryField = @Content WHERE Id = 73 ";
command.Parameters.Add(new SqlParameter("@Content", SqlDbType.VarBinary, -1));
//Serialize the multidimensional byte array to a byte[]
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
bf.Serialize(ms, byteArray);
//Set the serialized original array as the parameter value for the query
command.Parameters["@Content"].Value = ms.ToArray();
if (command.ExecuteNonQuery() > 0)
{
//This method returns the VarBinaryField from the database (what we just saved)
byte[] content = GetAttachmentContentsById(73);
//Deserialize Content to a multidimensional array
MemoryStream ms2 = new MemoryStream(content);
byte[,] fetchedByteArray = (byte[,])bf.Deserialize(ms2);
//At this point, fetchedByteArray is exactly the same as the original byte array
}
}
}
}
'IMAGE' è deprecato - per SQL Server ** ** 2005 e più recente, si dovrebbe sempre ** ** usare' varbinary (max) 'per la memorizzazione di qualsiasi tipo binario - se questo è una singola immagine o un matrice multidimensionale. E ** no ** i tuoi dati non saranno ** alterati in alcun modo - byte in, byte fuori, esattamente come li metti in primo piano –
Grazie fantastici .. E 'stato davvero utile ... E uno più cosa perché dici che IMAGE è deprecato .. C'è qualche svantaggio nell'usare IMAGE ..? Sto usando SQL Server 2005 – Gihan
PS: ho cercato su Google e ho ottenuto la risposta. grazie ancora. Spero che tu metta questa risposta come risposta, così posso farcela. Tra ecco il link per i tipi di dati più obsolete per chi vuole: http://social.msdn.microsoft.com/Forums/en/transactsql/thread/15f9e54c-18af-4f9a-8472-58fbd285a736 – Gihan