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.
DataGridView Controls to display data.
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;");
Dset = new DataSet(); //For XML
Dset1 = new DataSet(); //For OleDb
Dset2 = new DataSet(); //For SQL
- After Declaration, Now we make a
Procedure named LoadData () to
initialize the data from different databases and to display it into
respective DataGridView control.
public void LoadData()
//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",
dataGridView2.DataSource = Dset2.Tables["User_Info"];
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.
2 shows copying data from MS-Access to XML Data Source
3 shows copying data from XML to SQL Server Data Source
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
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.