Data Adapter is one of the component of Data Provider.
Introduction
Data Provider has 4 components. Among these 4 components, i have covered Data Adapter and two of its methods.
A Data Adapter is a bridge between the Data Source and the data set.Select,Insert,Update,Delete operations in the Data Source can be performed by data adapter. A Data Adapter contains a connection object and a command object. It manages data in a disconnected mode. And opens and closes connection automatically, when reading or writing to a database.
Fill()
Suppose, i have this table tblStock. Using the Fill() method, one can fetch the records from the Data Source.
From this interface, simply click the Show Button.
Output:
Code behind the Show Button.
Update()
Now suppose, i want to update the number of units in the tblStock table.
Suppose, i have entered 2 for Product Id box and 3 for Units. Now click the Update Button.
Code behind the Update Button.
The following table shows, record has been updated successfully. Previously, it was 20, but now it is only 17 for prod_id=2.
If i just comment the SqlCommandBuilder cmdBuilder=new SqlCommandBuilder(da);
The following error comes.
SqlCommandBuilder object is actually used to automatically generate Transact-SQL statements for single-table updates .
Now, i am going to insert a new record into the Data Source using the Update() method.
Enter Product_Id and Number of Units of my own choice and click the Insert button.
Code behind the Insert Button.
A new record is inserted at the end of the table tblStock.
Conclusion
Happy Reading!