Database Reference
In-Depth Information
drop table ImageTable
create table ImageTable
(
ImageFile nvarchar(20),
ImageData varbinary(max)
)");
}
private void PrepareInsertImages()
{
cmd.CommandText = @"insert into ImageTable
values (@ImageFile, @ImageData)";
cmd.Parameters.Add("@imagefile", SqlDbType.NVarChar, 20);
cmd.Parameters.Add("@imagedata", SqlDbType.Image, 1000000);
cmd.Prepare();
}
private void ExecuteInsertImages(int imageFileNumber)
{
string imageFileName = null;
byte[] imageImageData = null;
imageFileName = imageFilePrefix + imageFileNumber.ToString() + imageFileType;
imageImageData = LoadImageFile(imageFileName, imageFileLocation, maxImageSize);
cmd.Parameters["@ImageFile"].Value = imageFileName;
cmd.Parameters["@ImageData"].Value = imageImageData;
ExecuteCommand(cmd.CommandText);
}
private byte[] LoadImageFile(string fileName,string fileLocation,int maxImageSize)
{
byte[] imagebytes = null;
string fullpath = fileLocation + fileName;
txtLoadImages.AppendText("Loading File:");
txtLoadImages.AppendText(Environment.NewLine);
txtLoadImages.AppendText(fullpath);
FileStream fs = new FileStream(fullpath, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
imagebytes = br.ReadBytes(maxImageSize);
txtLoadImages.AppendText(Environment.NewLine);
txtLoadImages.AppendText("Imagebytes has length " +
imagebytes.GetLength(0).ToString() + "bytes.");
return imagebytes;
}
 
Search WWH ::




Custom Search