开发者

Can you use named parameters with an OdbcCommand?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜