开发者

C# bound table adapter not updating until called twice

New to C# from vb.net and I 开发者_运维问答am just making some mock bound applications for now. I have problems with the following code. If I pic an image and exit the application, there is no change. Even if I move a row. However if I upload an image, move to another row, then add another image. After exiting the application the first image will be there but not the second.

In short I have to attempt to upload to another record before the record I actually want updating will do so.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace DBUserManagement
{    
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'dsUsers.Users' table. You can move, or remove it, as needed.
            this.usersTableAdapter.Fill(this.dsUsers.Users);
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            if (DialogResult.OK == ofd.ShowDialog())
            {
                imgUser.SizeMode = PictureBoxSizeMode.StretchImage;
                imgUser.Image = new Bitmap(ofd.OpenFile());
                //update bound field.
                usersTableAdapter.Update(dsUsers);
            }
        }
    }
}

Any ideas on what I am missing or not understand correctly? Any help appreciated.

/P


The answer was I needed to call the BindingSource's .EndEdit(); method.

So I am guessing it was down to the binding source still having hold of something.

Seems like I'm on the right track anyhow, I looked up the details on MSDN :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜