Troubleshooting a Parameterized SQL Statement in asp

后端 未结 2 766
小鲜肉
小鲜肉 2021-01-13 09:18

I\'m trying to secure some legacy code written in what I guess is VB or asp(Not really sure if there is a difference). When I try to execute the statement the page gets an i

2条回答
  •  抹茶落季
    2021-01-13 09:36

    To use named parameters you need to enable NamedParameters.

    countCmd.NamedParameters = True
    

    But there's a limitation that affects you.

    In Adodb.Command, named parameters only work with stored procedures.

    For an ordinary query like yours, you need to use question mark placeholders instead of named ones.

    Then you can omit or specify a rubbish value for first parameter of the CreateParameter method.

    countCmd.NamedParameters = False
    countCmd.CommandText = "SELECT COUNT(*) FROM [table1] WHERE FY=?"
    countCmd.Parameters.Append countCmd.createparameter(, 200, 1, 255, fy)
    'countCmd.Parameters.Append countCmd.createparameter("@blablabla", 200, 1, 255, fy) 'this also works
    

提交回复
热议问题