我在將圖像轉換爲SQL Server中的字節後存儲圖像,但出現了問題,即無法將字節轉換爲字節[]。 這裏是代碼,請發送您寶貴的回覆。字節到字節[]轉換?
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (fpPhoto.HasFile)
{
if (fpPhoto.PostedFile.ContentType == "image/jpg" ||
fpPhoto.PostedFile.ContentType == "image/jpeg" ||
fpPhoto.PostedFile.ContentType == "image/png")
{
byte[] imagebytes = new byte[fpPhoto.PostedFile.ContentLength];
int filelenght = fpPhoto.PostedFile.ContentLength;
imagebytes = fpPhoto.FileBytes;
fpPhoto.PostedFile.InputStream.Read(imagebytes, 0, filelenght);
}
}
User objUser = new User();
objUser.UserName_Pk = txtUserName.Text;
objUser.Password = txtPassword.Text;
objUser.MobileNo = txtMobileNo.Text;
objUser.Email = txtEmail.Text;
objUser.SecurityAnswer = txtAnswer.Text;
objUser.Photo = Convert.ToByte(imagebytes); // Here Error occurs
objUserBll.InsertUpdate(objUser);
}
哪條線你有錯誤? –
什麼數據類型是'objUser.Photo'? – LGSon
Photo的數據類型是什麼? –