SQL Compact,新的数据集,标识列按相反顺序并且没有提交?
我为我的应用程序创建了一个新的 .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:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
AcceptChanges 后这些 ID 值会改变吗?
Do those ID values change after an AcceptChanges?