• Winform中使用PictureBox显示及修改数据库中的照片


        做了程序,需要管理人员信息,其中就有照片。一般来说这种blob字段的信息比较难搞定,后来发现在winform上放置picturebox并与bindingsource进行绑定后几乎都不用写代码可以轻松实现照片信息的修改和显示。不过实现的过程中走了不少弯路。

        picturebox的属性设置:(databindings)中的Image属性设置为人员的BindingSource中的相应照片字段。

        BindingSource对象所绑定的TableAdapt中的update和insert的command设置要注意,其中照片字段的参数属性providertype设置为longvarbinary或varbinary,长度为0.

        最要注意的问题是:不要使用access来向mdb的照片字段插入数据,否则无法显示。用自己的程序实现照片的插入。

        唯一需要编写代码的地方是picturebox控件的click事件,实现用户通过点击该控件可以把照片文件加载到picturebox控件,剩下的都交给vs自动完成(照片显示、修改到数据库等):

                OpenFileDialog openfile = new OpenFileDialog();
                String FileName 
    = "";
                
    if (openfile.ShowDialog() == DialogResult.OK)
                {
                    FileName 
    = openfile.FileName;
                    
    this.photo.Image = Image.FromFile(FileName);
                }

        因为使用了bindingnavigator等绑定控件,很多代码都省了,呵呵。

  • 相关阅读:
    hdu2328 Corporate Identity
    hdu1238 Substrings
    hdu4300 Clairewd’s message
    hdu3336 Count the string
    hdu2597 Simpsons’ Hidden Talents
    poj3080 Blue Jeans
    poj2752 Seek the Name, Seek the Fame
    poj2406 Power Strings
    hust1010 The Minimum Length
    hdu1358 Period
  • 原文地址:https://www.cnblogs.com/badwood316/p/2154653.html
Copyright © 2020-2023  润新知