我正在尝试通过以下代码将图像存储到数据库,但是它通过异常“NullReference exception”。当我调试这段代码时,'postedFile'为空......提前致谢
protected void btnAddUser_Click(object sender, EventArgs e)
{
userName = tbxUserName.Text;
password = tbxPassword.Text;
HttpPostedFile postedFile = FileUpload1.PostedFile;
string fileName = Path.GetFileName(postedFile.FileName);
string fileExtension = Path.GetExtension(fileName);
Stream stream = postedFile.InputStream;
BinaryReader binaryReader = new BinaryReader(stream);
byte[] bytes = binaryReader.ReadBytes((int)stream.Length);
string queryInsert = "insert into smart_shop.users(name,password,image) values('" + userName + "','" + password + "','" + bytes + "');";
dbObject.QueryFeeder(queryInsert);
}
答案 0 :(得分:-1)
最有可能的是,您需要添加enctype =" multipart / form-data"到你的表格标签。
实施例:
ng-click="hideBox()"