Click here to Skip to main content
15,885,875 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i want to save records from oracle database to sql database ,. there should be no duplication of ID number .
the data is very huge in " Lacks "

i just try to insert by code but it will take loads of time ,.
how should i use bulk insert i need PAT_NAME,PAT_ID, PATIENT_NO these three column from oracle , i have only view of that table,.,.



C#
protected void Button1_Click(object sender, EventArgs e)
       {
        string oradb = "Data Source=(DESCRIPTION=" + "(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=100.43.100.4)(PORT=1521)))"
              + "(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=HISP1)));" + "User Id=samir;Password=kodak;";
        OracleConnection conn = new OracleConnection(oradb);
        conn.Open();
        string sql = "select PAT_NAME,PAT_ID, PATIENT_NO from PAT_REG ";
           //where PATIENT_NO = '" + PatNo.Text + "'";
        OracleCommand cmd = new OracleCommand(sql, conn);
        cmd.CommandType = CommandType.Text;
        OracleDataReader dr = cmd.ExecuteReader();
        while (dr.Read())
        {
            TextBox1.Text = dr["PAT_ID"].ToString();
            TextBox2.Text = dr["PAT_NAME"].ToString();
            TextBox3.Text = dr["PATIENT_NO"].ToString();
            string sq = "Data Source=TRAINING-ROOM-8;Initial Catalog=ksmc;Integrated Security=True";
            SqlConnection con = new SqlConnection(sq);
            con.Open();
            string s = ("insert into test(PatID,Patname,Pat_ID_NO) values ('" + TextBox3.Text + "','" + TextBox2.Text + "','" + TextBox1.Text + "')");


            SqlCommand cmnd = new SqlCommand(s, con);
            cmnd.ExecuteNonQuery();
            TextBox1.Text = "";
            TextBox2.Text = "";
            TextBox3.Text = "";

        }

        conn.Close();
       }
Posted
Updated 11-Dec-12 19:17pm
v2
Comments
CHill60 10-Dec-12 6:03am    
Can you supply more information please? What code are you using to save the data? Are you only interested in new records?
Mohammed Abdul Muqeet 10-Dec-12 6:19am    
this code is use to fetch only by ID . i want to do it by time for every 5 hours the data should be fetch from oracle and save in sql
once the record is saved there should be no duplication of recoreds , only new records should be save in sql

1 solution

if only new records should be added you should first make update to make sure you only select new rows. I would probably add new column "processed" to oracle table bit/boolean that would state if record was already saved to sql.
Then Any record that is already saved into sql should have new property processed set to true.

Also why are you storing data from datareader into textbox? if it's for temporary storage you should rather use some simple class.

And if you are expecting that there will be lot's of data(at least thousands) every cycle you should consider using bulk insert.

Well for Bulk insert i would use codes from here
Bulk Insert in .NET applications: Part 1[^]

And because you have only view of table you can't add tag saying that it was already downloaded to sql server.
If you use SQL Server 2008 or later I woudl always add data to tmp table(it would be same table as tabe in which you want to save data) and Then use TSQL MERGE in stored procedure that could be called aso from your code or periodically by SQL Agent.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900