Updating dataset in c

Posted by / 08-Jan-2018 23:39

Updating dataset in c

So far, a change within the data-aware control has changed values in the field data link class.The final step in creating a data editing control is to update the dataset with the new value.

First you need to setup your connection.string Connection String = "server=" _Database Server ";user id=" User Name ";password=" Password "; Trusted_Connection=no;connection timeout=30"; Establish your connection Connection = new Sql Connection(Connection String); Connection. The problem is that when you Fill your Data Set by default it sets all Rows to a Row State of No Change.

Open(); Now we setup our adapterstring Parent Query = "SELECT * FROM Parent Table";string Child Query = "SELECT * FROM Child Table"; Sql Data Adapter Parent Adapter = new Sql Data Adapter(Parent Query, Connection); Sql Data Adapter Child Adapter = new Sql Data Adapter(Child Query, Connection); At this point we can fill our Data Set. Fill(My Data Set, "Child Table"); We have 1 Data Set with 2 Data Tables in it, Parent Table and Child Table. This means when you merge your 2 Data Sets nothing will get written to your database because nothing has changed.

Before we do we need to setup an event handler for updating the Identity column in each row when it gets written back to the database. The database has an Identity field and a Foregn Key constraint. This is done so that when we update the ID column for a row that ID gets propagated to any row within the child tables that contain the same Identity. Any new data should be marked as Added so the Adapter will Insert it into the database when you perform the Update.

Note: Keep in mind that this Update is different than a SQL UPDATE statement.

To insert, update, and delete data using a Data Adapter, you create an Ole Db Command object with INSERT, UPDATE, and DELETE statements and set the Insert Command, Update Command, and Delete Command properties of the data adapter to Ole Db Command.

updating dataset in c-87updating dataset in c-27updating dataset in c-87

As you proceed, remember that updating data is not the same process as entering new data.