Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#2.0 C#3.0 C# C#4.0 VB.NET
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=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 10-Dec-12 0:52am
Edited 11-Dec-12 20:17pm
v2
Comments
CHill60 at 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 at 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
good
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.
  Permalink  
v3

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

  Print Answers RSS
0 OriginalGriff 320
1 DamithSL 265
2 CPallini 235
3 Maciej Los 190
4 Sergey Alexandrovich Kryukov 184
0 OriginalGriff 5,415
1 DamithSL 4,422
2 Maciej Los 3,820
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,911


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 13 Dec 2012
Copyright © CodeProject, 1999-2014
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