For days I am struggling with the behavior of dataadapter queries.
A hint to get over this would really be appreciated.
I collected quite some experience in programming Visual Foxpro.
I like the concept of tableadapters, because I think these keep the code more readable as all the lines needed
for the management of the connections is kept in the background.
I do have this table in the database 'Zugriffe', which is part of the project:
CREATE TABLE [dbo].[tabelle1] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[Inhalt] NCHAR (10) NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
);
The table is currently comprising these values:
IDInhalt
2Test0
3Test1
4test2
5Test4
6Test5
Created the tableadapter 'tabelle1TableAdapter'.
Added the insert command 'InsertTesting' in the tableadapter:
INSERT INTO tabelle1
(Inhalt)
VALUES (@Inhalt);
SELECT SCOPE_IDENTITY()
Set the ExecuteMode to 'Scalar'.
Have this code executed in runtime:
--------------------------------------------------
//Create a dataset for the values in table tabelle1 before the insert commands
ZugriffeDataSet MyDataset = new ZugriffeDataSet();
//Create a dataset for the values in table tabelle1 after the insert commands
ZugriffeDataSet MyDatasetafterit = new ZugriffeDataSet();
//Initiate new instance of tabelle1TableAdapter
ZugriffeDataSetTableAdapters.tabelle1TableAdapter MyTableAdapter =
new ZugriffeDataSetTableAdapters.tabelle1TableAdapter();
//Fill dataset with values out of tabelle1 before insert commands
int nzahlFill = MyTableAdapter.Fill(MyDataset.tabelle1);
//Use standard insert command of tabelle1TableAdapter to upload data
string MyInhalt = "Erster";
int nzahl = MyTableAdapter.Insert(MyInhalt);
//Use self coded insert command to upload data
int new_ID = Convert.ToInt32(MyTableAdapter.InsertTesting("Test6"));
//Fill second dataset with content of tabelle1 after inserting
int nzahlFill2 = MyTableAdapter.Fill(MyDatasetafterit.tabelle1);
------------------------------------------------------------
This is happening:
- nzahl is set to 1 => 1 row is added
- new_ID is set to 8 => highest ID before running the code was 6. Two lines added: Latest ID now: 8
- MyDatasetafterit contains 7 lines including the ones just added
All as expected.
I end the debugging and look into tabelle1. Much to my surprise, I just see five lines.
Running the code again will have the exact same result, in particular, new_ID will be again 8.
Why can't I see the added lines in tabelle1, if I can see the two added lines in MyDatasetafterit?
Am I missing another command to constantly upload the content into tabelle1?
Thanks again.