views:

2284

answers:

3

Hi,

I am trying to add a row to a table in the database using the table adapter's update method. I am not getting any errors it looks like working fine but there is no actual insertion into the database. However if I try to insert the same row again I get a constraint exception saying that I am trying to insert a data that is already in the table. But in the end there is no data physically inserted into the table. I tried to use table adapter's insert method but I got the same error.

Where am I doing wrong? Thanks in advance.

Here is the code where insertion is made:(database name: pompadatabase, table name: pompa)

pompadatabaseDataSet.pompaRow tmprow; tmprow = pompadatabaseDataSet.pompa.NewpompaRow(); tmprow.isim = textBox5.Text; tmprow.info = richTextBox1.Text; tmprow.resim = bao; tmprow.seri_id = Convert.ToInt32(sinifBox.SelectedValue.ToString()); this.pompadatabaseDataSet.pompa.Rows.Add(tmprow); this.pompaTableAdapter.Update(this.pompadatabaseDataSet.pompa);

A: 

Havent done what you do before, but are you sure there is not a COMMIT function that actually SENDS the data to your DB?

I get the impression your datarow is in a layer(dataset) before the DB, so when you addd a the same record to your dataset it results in an error.

Look for a COMMIT or FLUSH method instead of Update maybe...?

Wolf5
+3  A: 

Where are you "physically" looking for the data ? i mean, are you checking upon the db instance you have in your solution explorer or in the one inside the debug folder ? When you run your application, a copy of the SQL Server CE db file will be put inside that folder and the rows will be saved there. Each time you re-run your application, that file will be overwritten. Try to run your application from that folder, if everything goes well, that was the problem. Well it could sound silly but it happened to me when i first started to work with DataSets and TableAdapters.

Stefano Driussi
that is the exact reason, thank you
A: 

the transaction of pompaTableAdapter needs to b commited. i.e urtransaction.Commit(); then look in Db ur data wud be saved.