unote 書けば書くほどに

20230101

///


/// update ボタンクリック時
///

private void button4_Click(object sender, EventArgs e)
{
OraTableUpdate();
}

public void OraTableUpdate()
{
Console.WriteLine("開始");

//データテーブル取得
string strSQL =
"select * " +
"from DEPT_BK";

DataTable dt = new DataTable();

dt = DBA2(strSQL);

foreach (DataColumn dc in dt.Columns)
{
//strSQL = "UPDATE DEPT_BK DBK SET DBK.DNAME = 'AAAAA' ";

strSQL =
"update DEPT_BK DBK " +
"set DBK." + dc.ColumnName + " = " +
"case when DBK.KOUSHINBI < (select D.KOUSHINBI from DEPT D where DBK.DEPTNO = D.DEPTNO) " +
"then (select D." + dc.ColumnName + " from DEPT D where DBK.DEPTNO = D.DEPTNO) END " +
"where exists (select * from DEPT D where DBK.DEPTNO = D.DEPTNO and D.KOUSHINBI > DBK.KOUSHINBI)";
//case when [更新日比較] then [更新する値代入] end
//where exist(select * ~:対象行のみを条件とする
 //参考:https://dream-target.jp/2018/02/17/130/
//https://dxo.co.jp/blog/archives/8971

dt = DBA2(strSQL);

Console.WriteLine(dc.ColumnName);
}

//グリッドビューにデータ表示
strSQL =
"select * " +
"from DEPT_BK";

dataGridView1.DataSource = DBA2(strSQL);

Console.WriteLine("完了");
}