Data Transfer Through Different Data Sources

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
  1. First we have to make some declaration as follows.
#region “Declaration”
                      //For Sql COnnection
SqlConnection SqlCon = new SqlConnection(“Integrated Security=True;Initial Catalog=SqlDB;Data Source=.\SqlExpress”);
                      SqlCommand SqlCmd;
                      //For OleDb Connection
OleDbConnection OleCon = new OleDbConnection(“Provider=Microsoft.Jet.OLEDB.4.0;   Data Source=..\..\AccessDB.mdb;”);
          OleDbCommand OleCmd;
        //For All DataSources
                    DataSet Dset = new DataSet();   //For XML DataSource
        DataSet Dset1 = new DataSet();  //For OleDb DataSource
        DataSet Dset2 = new DataSet();  //For SQL DataSource
                  DataRow row;
  1. 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);
            OleAdapt.Fill(Dset1, “User_Info”);
            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);
            SqlAdapt.Fill(Dset2, “User_Info”);
            dataGridView2.DataSource = Dset2.Tables[“User_Info”];
//Load the data from XML file to the dataGridView3
            dataGridView3.DataSource = Dset.Tables[“UserInfo”];
  1. Figure 1 shows the data into respective DataGridView at form load

Figure 1
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
  1. 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
  1. 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.
Mayur Dighe

Leave a Reply

Your email address will not be published. Required fields are marked *