BindingNavigator的“保存"按钮不会将数据保存到数据库 [英] BindingNavigator Save button doesn't save the data to database

查看:56
本文介绍了BindingNavigator的“保存"按钮不会将数据保存到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用sql数据库制作了一个C#程序.我是使用数据源中的拖放创建窗体的.但是当我按保存"按钮时,数据不会保存在数据库中.

I made a C# program with sql database. I created the Form using the drag and drop from the data source. but when I press in save button, the data doesn't save on the database.

自动创建的代码是

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

    private void tableTest3BindingNavigatorSaveItem_Click(object sender, EventArgs e)
    {
        Validate();
        this.tableTest3BindingSource.EndEdit();
        this.tableAdapterManager.UpdateAll(this.test3DataSet);
        //this.tableTest3TableAdapter.Update(this.test3DataSet.TableTest3); // I tried to add this line but it also not work !!

    }

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

    }
}
}

我必须添加一些代码或更改属性吗,顺便说一句,我是按照网站上的步骤创建数据库的,它必须正确.

Do I have to add some code or change properties, By the way I created the database following steps in website and it must be correct.

推荐答案

默认情况下,在解决方案资源管理器中,数据库设置为COPY ALWAYS到bin \ debug文件夹,这意味着该数据库已被应用程序中的一个覆盖文件夹.

By default in the solution explorer the database is set to COPY ALWAYS to the bin\debug folder which means that the database is alwys overwritten by the one in the application folder.

解决方案:您可以将此属性更改为请勿复制",并在需要时自行复制或将数据库保留在项目之外.当要求创建连接时将其带入项目时,sympy说不.否则,您应该将连接字符串目录更改为项目forlder中的数据库,而不是在debug文件夹中.应该可以.

Solution: You can change this property to DO NOT COPY and copy it yourself if when needed or leave the database out of the project. When asked to bring it in the project when creating a connection, sympy say no. or you should change the connection string directory to the database in the project forlder not in the debug folder. that should work.

这篇关于BindingNavigator的“保存"按钮不会将数据保存到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆