我在将图像转换为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的数据类型是什么? –