- What is Data Adapter?
- Primary Data Adapters for the databases.
- Data Adapter properties.
- Methods used by Data Adapter.
- How to create Data Adapter with an example?
- OleDbData Adapter, which is suitable for use with certain OLE DB providers.
- SQLDataAdapaters, which is specific to a Microsoft SQL server. This is faster than the OleDBDataAdapter. because it works directly with SQL servers and does not go through an OLE Db Layer.
- Select command retrieves rows from Data Source
- Insert command writes inserted rows from data set into Data Source
- Update command writes modified rows from data set into Data Source.
- Delete command deletes rows from Data Source.
- FillUse this method of a SQL data adapter to add or refresh row from a Data Source and place them in a Data Set table. The fill method uses Select statement, which is specified in the Select command property
- UpdateUse this method of data adapter object to transmit the changes to a dataset table to the corresponding Data Source. This method calls the corresponding insert, delete or update command for each specified row in a data table in a data set.
- CloseUse this method for the connection to a database.
- Creating Data Adapter with Example
The examples given below use a SQLDataAdapter object to define a query in the database.
using System; using System.Data; using System.Data.SqlClient; namespace DataAdapter { class Program { static void Main(string[] args) { string connectionString = @ "data source=localhost;initial catalog=northwind;integrated security = SSPI"; string commandString = @ "SELECT * from customers"; SqlDataAdapter da = new SqlDataAdapter(commandString, connectionString); DataSet ds = new DataSet(); DataAdapter.Fill(ds); DataTable dt = ds.Tables[0]; int rows = dt.Rows.Count; } } }
Hence, this is the way of how can we create Data Adapter object, using ADO.NET. Thanks for reading this article. Sharing is caring.
About the Author:
By nature I have a very curious and inquisitive mind. I like to do well into matters deeply and solve problems by using a lateral thinking approach coupled with strong analytical and evaluative skills, with the ability to articulate risk issues or concerns objectively. Besides these, I have an 5 years of exp. in IT Industry, Specially Software development and my area of interest is in SharePoint13,16,Office 365,MVC,C#,JavaScript,SQL,SSRS,Project Server etc.”
Achievements: C#MVP, Member of the Month (January)
Personal Blog: HTTP://PREMKT.BLOGSPOT.MY/
Linkedin: HTTPS://WWW.LINKEDIN.COM/IN/RATHROLLAPREMKUMAR/
Kumar, P. How To Create The Data Adapter Object Using ADO.NET by #RathrolaPremKumar. [online] Available at: http://premkt.blogspot.ie/2017/03/how-to-create-data-adapter-object-using.html [Accessed 5 Apr. 2017].