C# 绑定表适配器在调用两次之前不会更新

发布于 2024-12-09 10:22:11 字数 1360 浏览 0 评论 0原文

来自 vb.net 的 C# 新手,我现在只是制作一些模拟绑定应用程序。我对以下代码有问题。如果我拍摄图像并退出应用程序,则不会发生任何变化。即使我移动一排。但是,如果我上传图像,请移动到另一行,然后添加另一张图像。退出应用程序后,将出现第一张图像,但不会出现第二张图像。

简而言之,我必须尝试上传到另一条记录,然后我真正想要更新的记录才会这样做。

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);
            }
        }
    }
}

关于我缺少或不正确理解的内容有什么想法吗?任何帮助表示赞赏。

/P

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无敌元气妹 2024-12-16 10:22:11

答案是我需要调用 BindingSource 的 .EndEdit();方法。

所以我猜测这归因于绑定源仍然保留着某些东西。

无论如何,看来我走在正确的轨道上,我在 MSDN 上查找了详细信息:)

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 :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文