这个问题很常见 

在数据库连接的时候  没有将参数的传入到 数据库查询语句中 

 

以 sql server 数据库为例:

 

1 public static DataTable ExecuteQuerysql(string sql, params SqlParameter[] pams)
2 {
3 return ExecuteQuery(sql, CommandType.Text,pams);
4 }

 

 1 private static DataTable ExecuteQuery(string sql, CommandType ct, params SqlParameter[] pams)
 2         {
 3             using (SqlConnection con = new SqlConnection(str))
 4             {
 5                 using (SqlCommand com = new SqlCommand(sql, con))
 6                 {
 7                     com.Parameters.AddRange(pams);
 8                     com.CommandType = ct;
 9                     using (SqlDataAdapter sda = new SqlDataAdapter(com))
10                     {
11                         DataTable dt = new DataTable();
12                         sda.Fill(dt);
13                         return dt;
14                     }
15                 }
16             }
17         }

 

如果 在将ExcuteQuery重新封装的时候  把参数忘传了 就会出现这样的错误

相关文章:

  • 2021-10-18
  • 2022-12-23
  • 2022-01-13
  • 2022-12-23
  • 2022-03-10
  • 2021-12-08
  • 2022-12-23
  • 2021-11-18
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-10
  • 2022-12-23
  • 2022-02-24
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案