Transfer Data from and to MS-Access, SQL Server, and XML Data Sources
Generally, Transferring Data From one Type of Data Source to another and vice-versa is required when an application may have to deal with different the data sources at a time.
The article contains the simplest way to achieve the mentioned aim.
n Three DataGridView Controls to display data.
n Six Command Buttons to Perform associated actions
- First we have to make some declaration as follows.
SqlConnection SqlCon = new SqlConnection(“Integrated Security=True;Initial Catalog=SqlDB;Data Source=.\SqlExpress”);
OleDbConnection OleCon = new OleDbConnection(“Provider=Microsoft.Jet.OLEDB.4.0; Data Source=..\..\AccessDB.mdb;”);
DataSet Dset = new DataSet(); //For XML DataSource
DataSet Dset1 = new DataSet(); //For OleDb DataSource
DataSet Dset2 = new DataSet(); //For SQL DataSource
- After Declaration, Now we make a Procedure named LoadData () to initialize the data from different databases and to display it into respective DataGridView control.
//Load the data from MS-Access file to the dataGridView1
OleDbDataAdapter OleAdapt =
new OleDbDataAdapter(“Select * from User_Info Order By UserID”, OleCon);
dataGridView1.DataSource = Dset1.Tables[“User_Info”];
//Load the data from SQL file to the dataGridView2
SqlDataAdapter SqlAdapt =
new SqlDataAdapter(“Select * from User_Info Order By UserID”, SqlCon);
dataGridView2.DataSource = Dset2.Tables[“User_Info”];
//Load the data from XML file to the dataGridView3
dataGridView3.DataSource = Dset.Tables[“UserInfo”];
- Figure 1 shows the data into respective DataGridView at form load
|Figure 2 : Transferring a selected row from MS-Access Data Source to XML Data Source
Figure 3 : Transferring a row from XML Data Source to SQL Server Data Source
Figure 4 : Transferring a row from SQL Server Data Source to MS-Access Data Source
- To copy a row, first select the row from source DataGridView and click the respective button.
§ Figure 2 shows copying data from MS-Access to XML Data Source
§ Figure 3 shows copying data from XML to SQL Server Data Source
§ Figure 4 shows copying data from SQL Server to MS-Access Data Source
- We can also do the other operations mentioned in the program similarly as shown in Figure 1/2/3.
In this article, we see the transferring of data from one data source to another in C# Programming. We can also perform other operations on mentioned title such as Moving, Deleting or Inserting the data of single record or may of bulk records also.