Asp net updating database from dataset

So Let’s start with post with a very often situation in our coding life.Generally we used Data Set for having the collection of Data.

we will just focus on Concept and the code for this. Fill(ds); //Now here we are modifying record of student who has Student ID=1 and delete //the student ID "4" foreach (Data Row row in ds. As I told Data Set track changes to it’s row in the form of Row State. I will performe insert,delete and update operation on Data Set (Data Table) on Page_Load event. So we need to provide Insert, Update and Delete query to Sql Data Adapter object. Update(ds);// This method executes the appropiate query according to the //Row State NOTE : Please make sure that you have a primary key in your table. Here I want to let you know that every changes that we have done with dataset, Dataset retains the Row State value for each row and then according to this Row State value.It perform the appropriate operation(Insert or Update or Delete).

Now we use this Data Set as a Data Source of any of the Data Control like; Grid View, List View etc for showing this Data to User.Now sometime we have a requirement like, some rows of that Data Set (having Data Table) may get Updated with new values and some may have been Deleted or there may be another possibility of Insertion of new row in that table.

terrem43.ru

55 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>