GST Billing Software

header image

Difference between ControlAdapter and DataAdapter

Erachana Line

78. What is the difference between ControlAdapter and DataAdapter? How do they function? when are they used?

Please Refer the ContolAdapter Topic in https://erachana.in/software/c-sharp-build-expressions

DataAdapter is a Kushal Class which takes care of Database Communication Operations. When we run the application, it will initiate and one time data base credentials will be passed to this class. During other times, no need to pass the credentials again.

ControlAdapter Class uses the DataAdapter class internally with user friendly/pre-written functions which will help in database connection check, get the incremented key or check the proper values etc.

DataAdapter Class will run the given sql commands and store the results in DataSet of the entire database and keeps a object of the DataSet which can be used at later for some other operation if required.

When a command runs through control adapter, the control adapter will access the DataAdapter Class and do the database operations. In ControlAdapter class, the connection String is not available. And the ControlAdapter functions are pre-written code for developers to do database operations.

When a form is loading, the data can be filtered in 2 ways, one is by using ControlAdapter Class and another is By using DataAdapter Class.

When you need to fetch only fitered data with few conditions without sort option (OrderBy) in a query, you can use the ControlAdapter.Filter() Function to get the data from the database. This functio will only filter the data and assign the data to respective controls.

When you want to get filtered data with various query conditions (for more than 2 columns) then you can use DataAdapter Class.

DataAdapter.Current.LoadData - This function will help us to retrieve data by given query. The query may contain multiple conditions, joins, orderby conditions etc. It will return an object and assign the same object to datagrid by converting it to DataTable.


Example Code:


DataTable dtBill = (DataTable) DataAdapter.Current.LoadData("select * from Bill where TranType=" + trn_type + " order by BillDate desc, TranSeriesID, BillId desc", "Bill");
dgr1.DataSource = dtBill;

Note: While using DataAdapter.Current.LoadData function, first parameter is query, second parameter is TableName. Be careful while writing the TableName, it should be same case as in database design, or else an error will be thrown.