Update DataSet with the values of the inserted row

ChoKamir

Member
Joined
Nov 22, 2003
Messages
8
Location
Netherlands
Hey,



First of all i work with an access database. In my program i made an DataAdapter with retrieves rows from the database from two tables(through an inner join). Because the dataset linked to this DataAdapter is represented in a datagridview i also wrote insert, delete and update commands.

The way i solved the insert in two tables is with an transaction. In the RowUpdating event of the DataAdapter i create an transaction and manually insert the row in one of the tables. The insertcommand of the dataadapter will handle the insert in the other table. In the RowUpdated event of the dataadapter i commit the transaction.

This works all fine, except for the fact that some values in the datagrid are left empty because then the default values will be inserted and there is a column with a expression (calculating the product of two columns of a row). Now the default values wont appear nor will the column with the expression show a value. The reason for this is that the inserted data into the database is not returned to the dataset.

So how can i make sure that the actual data of the inserted row in the database is reflected to the dataset?



Thanks for helping

ChoKamir
 
PlausiblyDamp said:
You could just SELECT the results back into the dataset after your insert / update / delete has occurred.

Thanks for your answer, although i was hoping for an easier method. Because how i interpreted your answer is:
In the RowUpdated event i execute a command selecting the newly inserted row. I loop through the columns in the datareader and set them to the row by
e.Row.ItemArray.SetValue(reader,i). Although what ever i trie this function SetValue returns: Expression has been evaluated and has no value. Also when i user e.Row.ItemArray[2] = 0. No matter what i try it doesnt store the values. What am i doing wrong now?

Thanks
 
Back
Top