asp中表单上传图片后会解析成二进制byte数组保存到access数据库。
1、上传图片:
OpenFileDialog open = new OpenFileDialog();
// image filters
open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
if (open.ShowDialog() == DialogResult.OK)
{
// display image in picture box
pictureBox1.Image = new Bitmap(open.FileName);
// image file path
textBox1.Text = open.FileName;
}
2、保存图片信息到acess数据库。
C#实现,保存核心代码:
var pic = File.ReadAllBytes(yourFileName);
using(OleDbConnection con = new OleDbConnection(constr))
using(OleDbCommand cmd = new OleDbCommand("Insert Into DML_Books_List(ID, [Image]) values (@id, @image)", con))
{
con.Open();
cmd.Parameters.AddWithValue("@id", TextBox1.Text);
cmd.Parameters.AddWithValue("@image", pic);
cmd.ExecuteNonQuery();
}
这个不是经常用的吗,网上下一个无组件上传功能,然后套用到你的表单里不就行了吗?
上传图片和存入到数据库最两步操作。
上传功能上传到服务器上以后会返回一个服务端的图片路径,你只需要把这个图片路径存到数据库里就行。
上传图片的文件名