public void EditDept(Int32 DEPTNO, string DNAME, string LOC) {
string sql;
//パラメータは使いまわさないためメソッド内で宣言
DbParameter prmDEPTNO;
DbParameter prmDNAME;
DbParameter prmLOC;
//パラメータはバインド変数で渡す
sql = "Update DEPT set "
+ " DNAME = :DNAME,"
+ " LOC = :LOC"
+ " Where DEPTNO = :DEPTNO";
conn = this.DbConnect();
cmd = conn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = sql;
//パラメータ定義
prmDNAME = cmd.CreateParameter();
prmDNAME.Value = DNAME;
cmd.Parameters.Add(prmDNAME);
prmLOC = cmd.CreateParameter();
prmLOC.Value = LOC;
cmd.Parameters.Add(prmLOC);
prmDEPTNO = cmd.CreateParameter();
prmDEPTNO.Value = DEPTNO;
cmd.Parameters.Add(prmDEPTNO);
//UPDATE実行
cmd.ExecuteNonQuery();
} |