Click here to Skip to main content
13,353,322 members (48,559 online)
Rate this:
Please Sign up or sign in to vote.
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,.,.

protected void Button1_Click(object sender, EventArgs e)
        string oradb = "Data Source=(DESCRIPTION=" + "(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST="
              + "(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=HISP1)));" + "User Id=samir;Password=kodak;";
        OracleConnection conn = new OracleConnection(oradb);
        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);
            string s = ("insert into test(PatID,Patname,Pat_ID_NO) values ('" + TextBox3.Text + "','" + TextBox2.Text + "','" + TextBox1.Text + "')");

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


Posted 10-Dec-12 0:52am
Updated 11-Dec-12 20:17pm
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

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.180111.1 | Last Updated 13 Dec 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100