How to display specific database entries into a textbox on a WinForm application

后端 未结 3 1889
北荒
北荒 2021-02-06 19:39

UPDATE: Thanks everyone, the code was not the issue, although the information regarding SQL injection was useful, my issue was that I was using an older version of my database w

3条回答
  •  爱一瞬间的悲伤
    2021-02-06 20:15

    put a breakpoint on that line

    SqlDataReader re = cmd.ExecuteReader();
    

    and enter the following into textBox3

    '; DROP TABLE Product; SELECT '
    

    the ' are to be entered in your textbox. now execute your method and carefully read the resulting sql command... welcome to sql injection ;)

    @M Patel: thx for your comment and you are perfectly right

    The result would be the following SQL

    SELECT * FROM Product WHERE ProductID=''; DROP TABLE Product; SELECT ''
    

    And this would allow a malicious user to destroy your database.

    To prevent that you should work with prepared Statements like M Patel suggested in his answer

提交回复
热议问题