开发者

Can you use named parameters with an OdbcCommand?

开发者 https://www.devze.com 2023-01-30 13:38 出处:网络
I have a query like this: string command = @\"SELECT COUNT(*) as cnt, ( SELECT COUNT(*) FROM attend WHERE (DATEPART(WEEKDAY,start_date) = 2 OR DATEPART(WEEKDAY,start_date) = 6)

I have a query like this:

string command = @"SELECT COUNT(*) as cnt,
(
        SELECT COUNT(*) FROM attend
        WHERE (DATEPART(WEEKDAY,start_date) = 2 OR DATEPART(WEEKDAY,start_date) = 6)
            AND empl_no = ? and pay_code = '051'
                AND start_date BETWEEN ? AND ?
        ) as frimon
FROM attend as a
WHERE empl_no = ? and pay_code = '051'";

The only way I can figure out to s开发者_运维问答pecify a Parameter is with a ? (as opposed to using the @name method with a SQLCommand). This is forcing me to specify the same parameter multiple times (like for empl_no). Is there a way to use named parameters with OdbcCommands so I can just specify a named parameter once?


Unfortunately no. One way around this would be to roll your own class where you can define your own parameter collection and use token replacement.

0

精彩评论

暂无评论...
验证码 换一张
取 消