sir i have large access file wide 35 columns and 2300000 rows i have to pick randomly data where i have to join first,middle and last name and address too.
there is telephone which one i'm using as key but its working very slow...
my code is.....
// start calling jugad....
OleDbCommand coll = new OleDbCommand("select col from all_table", jug);
OleDbDataAdapter col_ad = new OleDbDataAdapter(coll);
DataTable col_dt = new DataTable();
int rw_no_col = col_ad.Fill(col_dt);
string accpath = "";
OleDbCommand accmd = new OleDbCommand("select DB_path,mode from jugad where id='1'", jug);
OleDbDataAdapter da = new OleDbDataAdapter(accmd);
DataTable dt = new DataTable();
da.Fill(dt);
accpath = dt.Rows[0]["DB_path"].ToString();
string mode_tb=dt.Rows[0]["mode"].ToString();
//start calling source file.....
OleDbConnection accconn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + accpath + "");
DataTable dt1 = new DataTable();
accconn.Open();
//source file connection open....
// Required calculation....
double val = double.Parse(textBox1.Text);
Int64 obtn = (long)(val * Int64.Parse(tat)) / 100;
// End calculation..
int index_value = 1;
OleDbCommand lst3_cmd = new OleDbCommand("select col from all_table", jug);
OleDbDataAdapter list3_da = new OleDbDataAdapter(lst3_cmd);
DataTable list3_dt = new DataTable();
list3_da.Fill(list3_dt);
int lst3_cunt = list3_dt.Rows.Count;
string[] lst3_item = new string[lst3_cunt];
for (int r = 0; r < lst3_cunt; r++)
{
lst3_item[r] = list3_dt.Rows[r][0].ToString();
}
string[] colnm = new string[rw_no_col];
Int32 no = (Int32.Parse(obtn.ToString())) / 100;
string[] frstcoll = new string[Int32.Parse(obtn.ToString())];
Int32 no1 = (Int32.Parse(obtn.ToString())) / 100;
// random number generating....
Int32[] rend = new Int32[obtn + 1];
Random rm = new Random();
for (int h = 0; h < Int64.Parse(obtn.ToString()); h++)
{
rend[h] = rm.Next(int.Parse(tat.ToString()));
}
// end.....
// data entry in temp....
int gh = 100;
float one_per = (float)int.Parse(obtn.ToString()) / 100;
int hg = 1;
for (int i = 0; i < rw_no_col; i++)
{
progressBar1.Value = 0;
if (i == 0)
{
// OleDbCommand addcol123=new OleDbCommand
colnm = col_dt.Rows[0].ToString();
label4.Text = "Database updating going on colunm " + colnm + "";
try
{
OleDbCommand addcol = new OleDbCommand("create table temp([" + colnm + "] char(255))", jug);
addcol.ExecuteNonQuery();
}
catch (Exception j)
{
}
OleDbCommand updatefin = new OleDbCommand("select ["+colnm+"] from [" + mode_tb + "]", accconn);
OleDbDataAdapter upf_da = new OleDbDataAdapter(updatefin);
DataTable upf_dt = new DataTable();
upf_da.Fill(upf_dt);
for (int k = 0; k <int.Parse(obtn.ToString()); k++)
{
label4.Text = "Database updating going on colunm " + colnm + "";
frstcoll[k] = upf_dt.Rows[rend[k]][colnm].ToString();
OleDbCommand updatef = new OleDbCommand("insert into temp([" + colnm + "])values('" + upf_dt.Rows[rend[k]][colnm].ToString() + "')", jug);
updatef.ExecuteNonQuery();
if ((int)((float)k / one_per) < gh)
{
if (hg < gh)
{
progressBar1.Value = hg;
hg++;
continue;
}
else
{
progressBar1.Value = 0;
hg = 1;
continue;
}
}
}
}
else
{
colnm = col_dt.Rows[0].ToString();
label4.Text = "Database updating going on colunm " + colnm + "";
progressBar1.Value = 0;
hg = 1;
/* OleDbCommand single_col = new OleDbCommand("select col from non_marge", jug);
OleDbDataAdapter s_c_da = new OleDbDataAdapter(single_col);
DataTable s_c_dt=new DataTable();
int mar_count = s_c_da.Fill(s_c_dt);
if (mar_count > 1)
{
for (int y = 0; y < mar_count; y++)
{
OleDbCommand addcol1 = new OleDbCommand("alter table temp add [" + colnm + "] char(255) ", jug);
addcol1.ExecuteNonQuery();
}
}*/
OleDbCommand addcol1 = new OleDbCommand("alter table temp add [" + colnm + "] char(255) ", jug);
addcol1.ExecuteNonQuery();
OleDbCommand pick = new OleDbCommand("select [lst_data] from [" + colnm + "]", jug);
OleDbDataAdapter temp_da = new OleDbDataAdapter(pick);
DataTable temp_dt = new DataTable();
temp_da.Fill(temp_dt);
string[] temp_store = new string[temp_dt.Rows.Count];
for (int g = 0; g < int.Parse(obtn.ToString()); g++)
{
string lst3_final = "";
for (int r = 0; r < temp_dt.Rows.Count; r++)
{
OleDbCommand updatefin1 = new OleDbCommand("select [" + colnm[0] + "],[" + temp_dt.Rows[r][0].ToString() + "] from [" + mode_tb + "] where [" + colnm[0] + "] = " + frstcoll[g] + "", accconn);
OleDbDataReader datarder = updatefin1.ExecuteReader();
while (datarder.Read())
{
lst3_final = lst3_final + " " + datarder.GetValue(1).ToString();
}
datarder.Close();
}
OleDbCommand updatef1 = new OleDbCommand("update temp set [" + colnm + "] = '" + lst3_final + "' where [" + colnm[0] + "] = '" + frstcoll[g] + "' ", jug);
//OleDbDataAdapter ghjk = new OleDbDataAdapter(updatef1);
updatef1.ExecuteNonQuery();
if ((int)((float)g / one_per) < gh)
{
if (hg < gh)
{
progressBar1.Value = hg;
hg++;
continue;
}
else
{
progressBar1.Value = 0;
hg = 1;
continue;
}
}
}
}
}
MessageBox.Show("DONE");
}
catch (Exception h)
{
MessageBox.Show(h.Message);
}
}
}