TableAdapter parameterized query

J

JR

I'll start off by saying I'm very new to VS2005 and the DB tools. I am
developing an app for Mobile 6 using SQL CE.

I have a table with a datetime field and I want to be able to query this
table for a given year. I have designed a query in the table's tableadapter
with the following SQL statement:
select date, ...
from table
where datepart(year, date) = @param1

When my code runs the FillBy method of the tableadapter it returns an
exception stating that there was an error parsing the query (basically the
"(" in line 3 of the sql statement is the culprit token).

I guess the question are:
Can I filter by year of a datetime field?
Is this a limitation of SQL CE?
Am I doing something wrong?

Thanks,
Jeremy
 
J

JR

Well, I was able to get it to work. The Configuration Wizard put brackets
around the word, datepart, and after I removed those brackets it seems to
work.

Although I have another question. The generated code for the
InitCommandCollection method (for my parameterized command) creates a line as
follows:

param.DbType = System.Data.DbType.AnsiString;

This line errors out and I have been commenting it out in order for the
program to continue to run.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top