The parameterized query expects the parameter which was not supplied

后端 未结 6 1102
甜味超标
甜味超标 2020-11-27 05:47

I\'m having a problem with my code:

Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged         


        
6条回答
  •  情书的邮戳
    2020-11-27 06:26

    Your website is in serious danger of being hacked.

    Read up on SQL Injection and how to prevent it in .NET

    Your query problem is the least of your concerns right now.

    But.....

    @Misnomer's solution is close but not quite there:

    Change your query to this:

    cmd.CommandText = "SELECT * FROM borrow where (Department LIKE '%@DepartmentText%')"
    

    and add parameters this way (or the way that @Misnomer does):

    cmd.Parameters.AddWithValue("@DepartmentText",TextBox2.Text)
    

    The important difference is that you need to change your CommandText.

提交回复
热议问题