はい、変更されていない多次元配列を返すことができます。
どうすればいいですか? Sql ServerのVarbinary(max)フィールドを使用し、シリアル化された多次元バイト配列を保存します。あなたの配列を元に戻すには、データベースに格納されているものを逆シリアル化する必要があります。ここで
はそれを行う方法の例です:
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'は廃止されました - SQL Server ** 2005以降で**バイナリタイプを保存するには常に** VARBINARY(MAX)を使用する必要があります。多次元配列。 ** **あなたのデータは**どのような方法でも変更されません** - 最初の場所に置いたバイト数、バイトアウト、正確に –
本当に助かりました。なぜIMAGEは廃止されたと言いますか..イメージを使用することの欠点はありますか?私はSQL Server 2005を使用しています – Gihan
PS:私はグーグルで答えを得ました。再度、感謝します。私はそれに目を向けることができるようにこれを答えとして入れて欲しい。ここには、非難されたデータ型のためのリンクがあります。http://social.msdn.microsoft.com/Forums/en/transactsql/thread/15f9e54c-18af-4f9a-8472-58fbd285a736 – Gihan