1、使用参数化SQL语句进行模糊查找的正确方法:

     //定义sql语句

      string sql = "SELECT StudentID,StudentNO,StudentName FROM Student WHERE StudentName like @StudentName";

      //给参数赋值

     command.Parameters.AddWithValue("@StudentName", txtStudentName.Text+"%");

 

2.错误做法1:

     //定义sql语句

      string sql = "SELECT StudentID,StudentNO,StudentName FROM Student WHERE StudentName like '@StudentName%'";

      //给参数赋值

     command.Parameters.AddWithValue("@StudentName", txtStudentName.Text);

 

 

3.错误做法2:

 

     //定义sql语句

 

      string sql = "SELECT StudentID,StudentNO,StudentName FROM Student WHERE StudentName like @StudentName%";

 

      //给参数赋值

 

     command.Parameters.AddWithValue("@StudentName", txtStudentName.Text);

相关文章:

  • 2021-05-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-08
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-19
  • 2022-12-23
  • 2021-10-07
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案