SQL Compact,新的数据集,标识列按相反顺序并且没有提交?

发布于 2024-10-05 22:00:35 字数 1008 浏览 16 评论 0原文

我为我的应用程序创建了一个新的 .dsf 数据库。我只添加了一个包含两列的表,“ID”(int,自动增量,step=1,start=1)和另一列名为 nchar 的“Name”。

然后我添加了一个新的数据网格,选择使用 dsf 数据库中的表创建的数据集(强类型数据集)。网格允许我添加新闻行,但“ID”列显示该行刚刚作为“-1”的 id 添加,依此类推添加更多行。

此外,.dsf 未进行任何更改。悲伤,我做错了什么?这让我发疯......

编辑参见下面的图片:简单的例子..我在表格中添加了几行(使用 Visual Studio 编辑器)。

    public Form1()
    {
        InitializeComponent();
        TabellaTableAdapter ta = new TabellaTableAdapter();
        ta.Fill(dataSet1.Tabella); // Fill the dataset with "Tabella" content
    }

    private void button1_Click(object sender, EventArgs e)
    {
        Data.DataSet1.TabellaRow newrow = dataSet1.Tabella.NewTabellaRow();
        newrow.Name = textBox1.Text; // Set the "Name" field
        dataSet1.Tabella.AddTabellaRow(newrow); // Add the new row
        dataSet1.Tabella.AcceptChanges(); // Commit
    }

按下按钮会创建这些新行(带有负 ID),并且不会将任何更改提交回数据库: 替代文本

I created a new .dsf database for my application. I added just one table with two columns, "ID" (int, auto-increment, step=1, start=1) and another column called "Name" of nchar.

Then I added a new datagrid, choosing the dataset (strongly typed one) created with the table from dsf database. The grid allows me to add news rows, but the column "ID" shows that the row just added as an id of "-1" and so on adding more rows.

In addition, no changes are made on .dsf. Sad, what I'm doing wrong? This is driving me crazy...

EDIT SEE PICTURE BELOW: simple example.. I added a few lines in the table (using visual studio editor).

    public Form1()
    {
        InitializeComponent();
        TabellaTableAdapter ta = new TabellaTableAdapter();
        ta.Fill(dataSet1.Tabella); // Fill the dataset with "Tabella" content
    }

    private void button1_Click(object sender, EventArgs e)
    {
        Data.DataSet1.TabellaRow newrow = dataSet1.Tabella.NewTabellaRow();
        newrow.Name = textBox1.Text; // Set the "Name" field
        dataSet1.Tabella.AddTabellaRow(newrow); // Add the new row
        dataSet1.Tabella.AcceptChanges(); // Commit
    }

Pressing the button creates those new rows (with negative ids) and no changes are commited back to the database:
alt text

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

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

发布评论

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

评论(1

诗酒趁年少 2024-10-12 22:00:35

AcceptChanges 后这些 ID 值会改变吗?

Do those ID values change after an AcceptChanges?

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