Declareer byte[] objData
buiten en voordat je blok gebruikt en probeer grootte in te stellen van byte-array:
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:om gegevens te lezen van 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);
}
}
}
}
Als alternatief kunt u DataAdapter/DataTable (code in OP) gebruiken
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);
}
}