Click here to Skip to main content
15,886,723 members
Home / Discussions / Web Development
   

Web Development

 
QuestionWireframe / Mockup tools Pin
C-P-User-317-Jun-15 7:10
C-P-User-317-Jun-15 7:10 
Question[CKEditor] How to search the contents in the string? Pin
Member 110547239-Jun-15 15:43
Member 110547239-Jun-15 15:43 
QuestionHTML5: Local Data Base. Pin
Member 117446415-Jun-15 4:18
Member 117446415-Jun-15 4:18 
AnswerRe: HTML5: Local Data Base. Pin
Simewu15-Jun-15 12:38
professionalSimewu15-Jun-15 12:38 
Questionproblem to check value array Pin
Loei Maleki4-Jun-15 1:52
Loei Maleki4-Jun-15 1:52 
AnswerRe: problem to check value array Pin
Loei Maleki4-Jun-15 1:57
Loei Maleki4-Jun-15 1:57 
QuestionCan't find where is the error from Pin
newbiejo2-Jun-15 22:50
newbiejo2-Jun-15 22:50 
QuestionUnable to stop SQL injection errors. Pin
Stephen Holdorf29-May-15 2:10
Stephen Holdorf29-May-15 2:10 
I finally get it. It's not just the code I use to execute the ExecuteScalar method but it is mainly the code up stream that is executing the class. It is everything calling your code. That said, now can I get someone to look at the up stream code causing my SQL injection errors. First I will show you two examples of the code calling my code, then the calling code, and finally the executing code, which I formulated and displayed from a previous post.

Calling code with Three parameters:

        public bool isTamAsp(int aspKey, int fy, string accountCode)
        {
            MyParam myParam;

            string sqlQuery = "select isTamMacom = count(macom_key) FROM hier_fy " +
                "WHERE hier_key = @aspKey AND fy = <a href="http://www.codeproject.com/Members/fy">@fy</a>  AND @accountCode NOT IN (3,4,7,8) AND macom_key IN (select hier_key from lkup_e581_MacomThatRequireTAM) AND is_visible = 1 AND is_active = 1";

            QueryContainer Instance = new QueryContainer(sqlQuery);

            myParam = new MyParam();

            myParam.SqlParam = new SqlParameter("@aspKey", Instance.AddParameterType(_DbTypes.Int));

            myParam.SqlParam.Value = aspKey;

            Instance.parameterList.Add(myParam);

            myParam = new MyParam();

            myParam.SqlParam = new SqlParameter("@fy", Instance.AddParameterType(_DbTypes.Int));

            myParam.SqlParam.Value = fy;

            Instance.parameterList.Add(myParam);

            myParam = new MyParam();

            myParam.SqlParam = new SqlParameter("@accountCode", Instance.AddParameterType(_DbTypes._string));

            myParam.SqlParam.Value = accountCode;

            Instance.parameterList.Add(myParam);

            if (Convert.ToInt32(ExecuteScaler(Instance)) < 1)
                return false;

            return true;
        }
<pre>

Calling code with no parameters:


<pre>

Calling code with no parameters:

<pre>

        public long GetMarinesUploadNextUploadKey()
        {
            string query = "SELECT MAX(upload_key) FROM temp_auth_usmc_upload";

            QueryContainer Instance = new QueryContainer(query);

            string result = Convert.ToString(ExecuteScaler(Instance));
            if (string.IsNullOrEmpty(result))
                return 1;
            else
                return Convert.ToInt64(result) + 1;
        } 

<pre>

Code calling my previous code with three parameters:

<pre>

        public bool isTamAsp(int aspKey, int fy, string accountCode)
        {
            return e581provider.isTamAsp(aspKey, fy, accountCode);
        }
<pre>

Method calling the SQL executing my code:


<pre>

                DbCommand command = _provider.CreateCommand();

                command.Connection = _connection;
                {
                    command.CommandText = Instance.Query;
                    command.CommandType = CommandType.Text;

                    if (Instance.parameterList.Count > 0)
                    {
                        foreach (var p in Instance.parameterList)
                        {
                            command.Parameters.Add(p.SqlParam);
                        }
                    }

                    if (_useTransaction) { command.Transaction = _transaction; }

                    try
                    {
                        returnValue = command.ExecuteScalar();
                    }

<pre>

My Class containing the SQL string and the cmd parameter List

<pre>

    public enum _DbTypes
    {
        Int = 1, _string = 2, _long = 3, _bool = 4, _DateTime = 5,
        _decimal = 6, _float = 7, _short = 8, _bite = 9
    } 

    public class MyParam
    {
        public SqlParameter SqlParam { get; set; }
    }
    /// <summary>
    /// Summary description for QueryContainer SGH
    /// </summary>
    public class QueryContainer
    {

        string _query;

        public List<myparam> parameterList = new List<myparam>();

        public QueryContainer(string query) { _query = query; }

        public SqlDbType AddParameterType(_DbTypes id)
        {
            switch (id)
            {
                case _DbTypes.Int:
                    return (SqlDbType)Enum.Parse(typeof(SqlDbType), "int", true);
                case _DbTypes._string:
                    return (SqlDbType)Enum.Parse(typeof(SqlDbType), "NVarChar", true);
                case _DbTypes._long:
                    return (SqlDbType)Enum.Parse(typeof(SqlDbType), "SqlDbType.BigInt", true);
                case _DbTypes._bool:
                    return (SqlDbType)Enum.Parse(typeof(SqlDbType), "SqlDbType.Bit", true);
            }

            return SqlDbType.VarChar;

        }

        public string Query
        {
            get
            {
                return _query;
            }

            set { _query = value; }
        }
    }
<pre>

AnswerRe: Unable to stop SQL injection errors. Pin
Sascha Lefèvre29-May-15 2:55
professionalSascha Lefèvre29-May-15 2:55 
GeneralRe: Unable to stop SQL injection errors. Pin
Stephen Holdorf29-May-15 4:03
Stephen Holdorf29-May-15 4:03 
GeneralRe: Unable to stop SQL injection errors. Pin
Sascha Lefèvre29-May-15 4:10
professionalSascha Lefèvre29-May-15 4:10 
GeneralRe: Unable to stop SQL injection errors. Pin
Richard Deeming29-May-15 4:11
mveRichard Deeming29-May-15 4:11 
GeneralRe: Unable to stop SQL injection errors. Pin
Stephen Holdorf29-May-15 8:55
Stephen Holdorf29-May-15 8:55 
GeneralRe: Unable to stop SQL injection errors. Pin
Richard Deeming29-May-15 9:14
mveRichard Deeming29-May-15 9:14 
GeneralRe: Unable to stop SQL injection errors. Pin
Sascha Lefèvre29-May-15 12:55
professionalSascha Lefèvre29-May-15 12:55 
QuestionHow to get my "wp_nav_menu()" function working Pin
Truck5328-May-15 16:34
Truck5328-May-15 16:34 
QuestionHost Windows Class Library in PHP Pin
Jassim Rahma27-May-15 0:49
Jassim Rahma27-May-15 0:49 
QuestionMessage Removed Pin
22-May-15 4:28
Antonio Guedes22-May-15 4:28 
QuestionOpening an existing project in WordPress Pin
indian14321-May-15 21:21
indian14321-May-15 21:21 
AnswerRe: Opening an existing project in WordPress Pin
User 171649221-May-15 22:11
professionalUser 171649221-May-15 22:11 
QuestionImproper Neutralization of special elements used in an sql command Pin
Stephen Holdorf12-May-15 10:09
Stephen Holdorf12-May-15 10:09 
AnswerRe: Improper Neutralization of special elements used in an sql command Pin
Sascha Lefèvre12-May-15 10:33
professionalSascha Lefèvre12-May-15 10:33 
GeneralRe: Improper Neutralization of special elements used in an sql command Pin
Steve Holdorf12-May-15 12:38
Steve Holdorf12-May-15 12:38 
GeneralRe: Improper Neutralization of special elements used in an sql command Pin
Sascha Lefèvre12-May-15 12:54
professionalSascha Lefèvre12-May-15 12:54 
GeneralRe: Improper Neutralization of special elements used in an sql command Pin
Steve Holdorf12-May-15 13:01
Steve Holdorf12-May-15 13:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.