0
我有代號的一部分,其插入DB SQL SERVER的圖像更新,但是當我再次嘗試重新插入我有,關鍵是重複的,所以我在尋找一個錯誤一種方式插入圖像,如果它的存在,它會更新一個我,這是我的代碼在數據庫中插入:插入圖像,如果它存在
if (ImageUpload.HasFile && ImageUpload.PostedFile.ContentLength > 0)
{
string filename = ImageUpload.FileName;
byte[] filebyte = ImageUpload.FileBytes;
Binary binaryObj = new Binary(filebyte);
DataClasses1DataContext context = new DataClasses1DataContext();
context.ImageStorage.InsertOnSubmit(
new ImageStorage
{
PPR = Convert.ToInt32(Session["Code"]),
ImageContentType = ImageUpload.PostedFile.ContentType,
ImageName = filename,
ImageBinary = binaryObj
});
context.SubmitChanges();
this.LabelInfo.ForeColor = Color.Green;
this.LabelInfo.Text = "Upload ok.";
}
catch(Exception xcp)
{
this.LabelInfo.Text = xcp.Message;
this.LabelInfo.ForeColor = Color.Red;
}
}
編輯:
這是我的表(圖片)列:
imgid:PK詮釋PPR F:ķINT圖像:VARBINARY圖片二進制:圖片名稱:VARCHAR
是什麼ImageStorage表的架構和列是主鍵? –
這個'C'如何? – Sadique
我想插入或更新圖像(如果存在)根據其他表中的列這個這個colomn是「PPR」,我用這種方式:PPR = session [「Code」] – Meryem