以前にそれを行ったことがありますが、この場合insert into table
、ターゲット テーブルの列の値が別のクエリの結果として得られるクエリがあります。それを持っていると、私parametarized query
のが正しい方法でフォーマットされているかどうかわかりません。
Sql Injection
修正前の元のクエリは次のとおりです。
cmd.CommandText += "insert into controlnumber (controlnumber, errorid)
values ('" + ControlNumber + "', (select errorid from error where
errordescription = '" + ErrorDescription + "' and errortype = '" +
ErrorType + "' + and applicationid = " + ApplicationID + " and statusid =
" + StatusID + " and userid = " + UserID + " and errortime = '" +
ErrorTime + "');";
これは、修正を試みた後のクエリですSql Injection
。
cmd.CommandText = "insert into ControlTable(ControlNumber, ErrorID)
values (@ControlNum, (select errorid from error where errordescription =
@ErrorDescription and errortype = @errorType and applicationid =
@ApplicationID and statusid = @StatusID and userid = @UserID and
errortime = @ErrorTime)"
ここにパラメータを追加します。
.....
command.CommandType = CommandType.Text
command.Parameters.AddWithValue("@ErrorDescription ", ErrorDesc);
command.Parameters.AddWithValue("@ControlNum", cntNumber);
command.Parameters.AddWithValue("@errorType",ErrorType);
command.Parameters.AddWithValue("@ApplicationID",AppID);
command.Parameters.AddWithValue("@StatusID",StatusID);
command.Parameters.AddWithValue("@UserID",UserID);
....私CommandText
のが正しい方法でフォーマットされているかどうか疑問に思っています。
ありがとう