Mehmet Yilmaz

Mehmet Yilmaz

  • NA
  • 29
  • 2.2k

C# dding data from parameter "access" to "Datatable"

Oct 15 2018 4:45 PM
Hi,
 
The following is added to the acces table with "using" in the code painted with the red. this takes a long time if the number of lines is too high. so how can I translate this section to the "Datatable" object
 
Exam :
DataTable dt = new DataTable();
dt.Columns.Add("periodclumb", typeof(string));
....
??????
void start()
{
for (int i = 0; i < datagrid1.RowCount; i++)
{
if (datagrid1.Rows[i] != null && datagrid1.Rows[i].Cells[1].Value != null)
{
DateTime d = DateTime.Parse(datagrid1.Rows[i].Cells[1].Value.ToString());
Insertrow(d.ToString("dd.MM.yyyy"));
}
}
void Insertrow(string cell)
{ DateTime period;
string ncell = cell.Replace('.', '-');
if (DateTime.TryParseExact(ncell, "dd-MM-yyyy", null, DateTimeStyles.None, out period))
{ Insertperiod(period.AddMonths(-1)); Insertperiod(period); } }
void Insertperiod(DateTime period)
{
using (var conn = new OleDbConnection("Provider=" + "Microsoft.Jet.OLEDB.4.0" + "; Data Source=" + mdbpatch))
using (var cmd1 = conn.CreateCommand())
{
cmd1.Connection.Open();
cmd1.CommandText = "insert into billtable (periodclumb) values (?)";
cmd1.Parameters.AddWithValue("?", period.ToString("MM/yyyy").Replace('.', '/'));
cmd1.ExecuteNonQuery();
}
}

Answers (2)