In my C# project..
I have Sql Database with data of 700 MB... I'm redesign tables and
relations and need to retrieve my data in the new tables..
I'm using SqlAdapter to Get old tables in my dataset then use the
GetChildRows()... insert new records in the new tables.
Here is the code which convert first 2 tables to 3 new tables:-
####### CODE START #######################
private void btn_Start_Click(object sender, System.EventArgs e)
{
this.transActionStart();
}
private void transActionStart()
{
progressBar1.Value = 0;
adp_Old_E7sea2ya.Fill(dsOld.E7saeya_List);
adp_Old_Country_list.Fill(dsOld.E7saeya_Country_Li st);
adp_Old_Mo2shrat.Fill(dsOld.E7saeyaDetails);
adp_Old_Mo2_Details.Fill(dsOld.E7saeya_Main);
progressBar1.Maximum = dsOld.E7saeya_List.Rows.Count;
this.setAhsa2yat();
}
private void setAhsa2yat()
{
ni_Ahsa2yat = new NewIndex();
foreach (DataSetOld.E7saeya_ListRow row in dsOld.E7saeya_List)
{
int ah_id = ni_Ahsa2yat.GetIndex("Ahsa2yat");
int succ = this.sqlCommandParam(Ins_Ahsa2ya, ah_id, row.E7saeya_Name);
if (succ == 1)
{
ni_Ahsa2yat.UpdateIndex("Ahsa2yat");
DataSetOld.E7saeya_Country_ListRow[] rows=
(DataSetOld.E7saeya_Country_ListRow[])row.GetChildRows("Rel_AH_Country");
this.setCountries(rows, row.E7saeya_ID, ah_id);
}
System.Threading.Thread.Sleep(1);
progressBar1.Value += 1;
}
Conn.Close();
}
private void setCountries(DataSetOld.E7saeya_Country_ListRow[]
e7saeya_Country_ListRows, int old_E7sa2ya_ID, int new_A7sa2ya_ID)
{
ni_Country = new NewIndex();
foreach (DataSetOld.E7saeya_Country_ListRow row in e7saeya_Country_ListRows)
{
DataSetOld.E7saeyaDetailsRow[] rows =
(DataSetOld.E7saeyaDetailsRow[])row.GetChildRows("Rel_Country_Mo2");
int country_id = ni_Ahsa2yat.GetIndex("Country");
int sucess =
this.sqlCommandParam(Ins_Country,country_id,row.E7 saeya_Country_Name);
if(sucess == 1)
{
ni_Country.UpdateIndex("Country");
this.setAHCountry(rows, row.E7saeya_Country_ID, new_A7sa2ya_ID, country_id);
}
else
{
SelCountryID.Parameters["@NAME"].Value = row.E7saeya_Country_Name;
int exist_id = (int)SelCountryID.ExecuteScalar();
this.setAHCountry(rows, row.E7saeya_Country_ID, new_A7sa2ya_ID, exist_id);
}
}
}
private void setAHCountry(DataSetOld.E7saeyaDetailsRow[] e7saeyaDetailsRows,
int old_AH_Country_ID, int new_A7sa2ya_ID, int new_country_id)
{
ni_Ah_Country = new NewIndex();
int ah_country_id = ni_Ah_Country.GetIndex("Ahsa2_Country");
int success =
this.sqlCommandParam(Ins_AhCountry,ah_country_id,n ew_A7sa2ya_ID,new_country_
id);
if(success == 1)
{
ni_Ah_Country.UpdateIndex("Ahsa2_Country");
setMo2shrat(e7saeyaDetailsRows, old_AH_Country_ID, ah_country_id);
}
}
################ CODE END ####################
My Company was using Delphi and I'm megrate everything to C#.. My way work
well but take to much time and memory, The old Delphi Code was doing this
task in 20% of the time and don't use so much system resources like mine?!
Is there better way to copy my data with the new shcema??
thanx