Ayrıca datagridviev'e ikinci bir veri yüklemesinde satırlar mükerrer görünüyor. Genel olarak işlenmemiş veriyi tekrar yüklesem bile datagrid mükerrer gösteriyor.
Kodum Aşağıdadır ve Projem Ektedir. Yardımlarınızı Rica Ediyorum.
public string patch = Application.StartupPath + "\\data.mdb";
private void Form1_Load(object sender, EventArgs e)
{
billload();
periodload();
}
public void periodload()
{
OleDbConnection con_kdv = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source =" + patch);
OleDbDataAdapter da_kdv = new OleDbDataAdapter("SElect *from period", con_kdv);
DataSet ds_kdv = new DataSet();
con_kdv.Open();
da_kdv.Fill(ds_kdv, "period");
periodgrid.DataSource = ds_kdv.Tables["period"];
con_kdv.Close();
}
public void billload()
{
OleDbConnection faturayuklecon = new OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0; Data Source =" + patch);
OleDbDataAdapter faturayukleda = new OleDbDataAdapter("SElect *from bill", faturayuklecon);
DataSet faturayukleds = new DataSet();
faturayuklecon.Open();
faturayukleda.Fill(faturayukleds, "bill");
billgrid.DataSource = faturayukleds.Tables["bill"];
faturayuklecon.Close();
int ilkonsay;
ilkonsay = billgrid.RowCount; int bi = ilkonsay - 1;
rowlabel.Text = bi.ToString();
}
private void button1_Click(object sender, EventArgs e)
{
periodemtyrowadd();
}
public void periodemtyrowadd()
{
OleDbConnection connection = new OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0; Data Source =" + patch);
connection.Open();
OleDbCommand kdvsil = new OleDbCommand("DELETE FROM period WHERE ID", connection);
kdvsil.ExecuteNonQuery();
try
{
for (int i = 0; i < billgrid.RowCount; i++)
{
if (billgrid.Rows != null && billgrid.Rows.Cells[1].Value != null)
{
DateTime d = DateTime.Parse(billgrid.Rows.Cells[1].Value.ToString());
InsertRow(d.ToString("dd.MM.yyyy"));
}
}
}
catch
{
MessageBox.Show("Bill Date Sorting Error ...!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
connection.Close();
perioddublicatedrowclean();
periodload();
}
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 =" + patch))
using (var cmd1 = conn.CreateCommand())
{
cmd1.Connection.Open();
cmd1.CommandText = "insert into period (a) values (?)";
cmd1.Parameters.AddWithValue("?", month.ToString("MM/yyyy").Replace('.', '/'));
cmd1.ExecuteNonQuery();
}
}
int kdvsil1, kdvsil2;
public void perioddublicatedrowclean()
{
OleDbConnection con = new OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0; Data Source =" + patch);
DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter("select * from period", con);
con.Open();
da.Fill(ds, "period");
for (int i = 0; i < ds.Tables["period"].Rows.Count; i++)
{
DataRow row = ds.Tables["period"].Rows;
kdvsil2++;
for (int j = kdvsil2; j < ds.Tables["period"].Rows.Count; j++)
{
DataRow row2 = ds.Tables["period"].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();
}
public void kdvsila(int num)
{
OleDbConnection con = new OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0; Data Source =" + patch);
con.Open();
OleDbCommand c = new OleDbCommand("Delete from period where ID =?", con);
c.Parameters.AddWithValue("ID", num);
c.ExecuteNonQuery();
con.Close();
}