I usually create parameterized queries to avoid SQL Injection attacks. However, I have this particular situation where I could not fully fulfill it:
public DataSet getLiveAccountingDSByParameterAndValue(string parameter, string value) { string sql = "select table_ref as Source, method as Method, sip_code as Code, " + " from view_accountandmissed " + " where " + parameter + " like @value " + " order by time DESC "; MySqlCommand cmd = commonDA.createCommand(sql); cmd.Parameters.Add("@value", MySqlDbType.String); cmd.Parameters["@value"].Value = "%" + value + "%"; MySqlDataAdapter objDA = commonDA.createDataAdapter(cmd); DataSet objDS = new DataSet(); objDA.Fill(objDS); return objDS; }
As you can see, I create @value as a parameter, but if I tried to do the same with the parameter, the request would fail.
So, is there a risk of SQL injection with this query? Also note that the parameter is set using DropDownList SelectedValue (not TextBox, so input is limited). If so, how can I improve this query?
source share