Argh! I am getting "duplicate parameter" errors with the following
prepared SqlCeCommand: (The important line is the next to the last line
with @kid_id).
select e.entry_id,
convert(nvarchar(10), e.entry_date, 101),
e.entry_title,
e.entry_text,
e.minutes_spent,
e.entry_date
from ud_entry as e
where e.entry_date >= @start_date
and e.entry_date <= @end_date
and exists
(select *
from ud_entry_to_kid as iek
where e.entry_id = iek.entry_id
and (iek.kid_id = @kid_id or @kid_id = -1) )
order by e.entry_date, e.priority
If I try to run this, I get:
{"Duplicated parameter names are not allowed. [Parameter name =
@kid_id]"}
If I remove the "or @kid_id = -1", the command compiles and runs
correctly. Apparently, I can only put the @kid_id parameter in the
query once. From the behavior, this seems like a deliberate limitation.
(!)
Has anyone seen this before? Suggestions for working around?
Using SQL CE 3.1.
Thanks for any advice.
Matt
partial stack trace:
Duplicated parameter names are not allowed. [ Parameter name = @kid_id
]
at System.Data.SqlServerCe.SqlCeCommand.CompileQueryPlan()
at System.Data.SqlServerCe.SqlCeCommand.ExecuteCommand
(CommandBehavior behavior, String method, ResultSetOptions options)
at System.Data.SqlServerCe.SqlCeCommand.ExecuteDbDataReader
(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader
(CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset,
DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String
srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables,
Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior
behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
Jin - 24 Jul 2008 02:02 GMT
> Argh! I am getting "duplicate parameter" errors with the following
> prepared SqlCeCommand: (The important line is the next to the last line
[quoted text clipped - 51 lines]
> behavior)
> at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
If I read the situation correctly, then simply using a different
parameter name (i.e. @kid_id2) should do the trick.
After all, these parameters are simply placeholders. Just make sure
you reference the same parameter name when supplying the actual
values.
- Jin
Matt - 24 Jul 2008 05:26 GMT
Jin <jinsoochang@gmail.com> wrote in news:689f4ae3-1393-44b3-bcd2-
6d9614de2a44@t54g2000hsg.googlegroups.com:
<snip "Duplicated parameter names are not allowed" discussion>
> If I read the situation correctly, then simply using a different
> parameter name (i.e. @kid_id2) should do the trick.
[quoted text clipped - 3 lines]
>
> - Jin
Doh! You do read the situation correctly, and simply adding another
parameter with a different name but the same value does solve the problem.
I feel silly that I didn't think of this myself, but thank you very much
for the suggestion.
Matt