C# ACCES TABLE TO DATATABLE DATA TRANSFER WITH PARAMETERS

  • Thread starter Thread starter mfyildiz
  • Start date Start date
M

mfyildiz

Guest
Hello there,
The following code is a data transfer from "acces" to "acces". Then duplicate lines are deleted.

How to transfer data from "acces" to "datatable" with the parameter as in the following code.

Because more than 20-30 lines of data processing takes too long.


My code;

public string tempyol = "C:\\test.mdb";

void start()
{
emptyperiodadd();
dublicatedrowclean();
}


void emptyperiodadd()
{
for (int i = 0; i < dataGridView1.RowCount; i++)
{
if (dataGridView1.Rows != null && dataGridView1.Rows.Cells[1].Value != null)
{
DateTime d = DateTime.Parse(dataGridView1.Rows.Cells[1].Value.ToString());
InsertRow(d.ToString("dd.MM.yyyy")); }
}
}

void InsertRow(string cell)
{
DateTime month;
string ncell = cell.Replace('.', '-');
if (DateTime.TryParseExact(ncell, "dd-MM-yyyy", null, DateTimeStyles.None, out month))
{
InsertMonth(month.AddMonths(-1));
InsertMonth(month);
}
}

void InsertMonth(DateTime month)
{
using (var conn = new OleDbConnection("Provider=" + "Microsoft.Jet.OLEDB.4.0" + "; Data Source=" + tempyol))
using (var cmd1 = conn.CreateCommand())

{
cmd1.Connection.Open();
cmd1.CommandText = "insert into kdv (a) values (?)";
cmd1.Parameters.AddWithValue("?", month.ToString("MM/yyyy").Replace('.', '/'));
cmd1.ExecuteNonQuery();
}

int kdvsil1, kdvsil2;

private void dublicatedrowclean()
{
OleDbConnection con = new OleDbConnection("Provider=" + "Microsoft.Jet.OLEDB.4.0" + "; Data Source=" + tempyol);
DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter("select * from kdv", con);
con.Open();
da.Fill(ds, "kdv");
for (int i = 0; i < ds.Tables["kdv"].Rows.Count; i++)
{
DataRow row = ds.Tables["kdv"].Rows;
kdvsil2++;
for (int j = kdvsil2; j < ds.Tables["kdv"].Rows.Count; j++)
{
DataRow row2 = ds.Tables["kdv"].Rows[j];
if (row.ItemArray.GetValue(1).ToString() == row2.ItemArray.GetValue(1).ToString())
{
if (row.ItemArray.GetValue(3).ToString() == row2.ItemArray.GetValue(3).ToString())
{
kdvsil1 = int.Parse(row2.ItemArray.GetValue(0).ToString());
kdvsila(kdvsil1);
}
}
}
}
con.Close();
}

private void kdvsila(int num)
{
OleDbConnection con = new OleDbConnection("Provider=" + "Microsoft.Jet.OLEDB.4.0" + "; Data Source=" + tempyol);
con.Open();
OleDbCommand c = new OleDbCommand("Delete from kdv where ID =?", con);
c.Parameters.AddWithValue("ID", num);
c.ExecuteNonQuery();
con.Close();
}

Continue reading...
 
Back
Top