简体   繁体   中英

SQL Compact, new DataSet, identity column in reverse order and no commit?

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: 替代文字

接受更改后,这些ID值会更改吗?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM