Dichiara byte[] objData
all'esterno e prima di usare il blocco e prova a impostare la dimensione di matrice di byte:
byte []objData=null;
using (MemoryStream memStream = new MemoryStream())
{
using (FileStream fileStream = File.Open(txtDICOMFilePath.Text, FileMode.Open))
{
fileStream.CopyTo(memStream);
}
int intL = Convert.ToInt32(memStream.Length);
objData = new byte[intL];
memStream.Read(objData,0,objData.Length);
}
SqlCom.Parameters.Add("@ImageData",SqlDb.Image,objData.Length).Value=objData;
EDIT:per leggere i dati da ImagesStore
string qry = "select * From ImagesStore";
using(SqlConnection Cn=new SqlConnect(CnStr))
{
using(SqlCommand SqlCom = new SqlCommand(qry, CN))
{
Cn.Open();
using(SqlDataReader dr=SqlCom.ExecuteReader())
{
while(dr.Read())
{
string path="x:\\folder\\" + dr[0] + ".png";
byte []bytes=(byte[])dr[1];
System.IO.File.WriteAllBytes(path,bytes);
}
}
}
}
In alternativa puoi usare DataAdapter/DataTable (codice in OP)
if (dt.Rows.Count > 0)
{
foreach(DataRow row in dt.Rows)
{
string path="x:\\folder\\" + row[0] + ".png";
byte []bytes=(byte[])row[1];
System.IO.File.WriteAllBytes(path,bytes);
}
}