Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Selecting dates in a Web form
Message
From
30/05/2007 17:08:16
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01229139
Message ID:
01229452
Views:
80
>Hi Folks.
>I am trying to use paramters in a SQL statement bu am getting an error:
>SqlException (0x80131904): Must declare the scalar variable
>
>My syntax is like:
> lcSelect = "DOC_DATE > = " + " @ldFrom " + " AND DOC_DATE < = " + " @ldTo " ;
>....This is added to the other bits of a a sql statement
>The ldFrom and ldTo are local datetime variables which have been initialised from a datetime session variable
>
>Am I missing something here ? Do I have to issue some sort of a parameter statement somewhere else ?
>
>Regards,
>Gerard

Gerard,
This is not what I meant when I said use parameters. You are not using parameters with this code, you're only hardcoding again usişng variables. What I meant was like this:
OleDbCommand cmd  = 
  new OleDbCommand("select * from myTable where DOC_Date between ? and ?", con );
cmd.Parameters.Add("dFrom",OleDbType.Date).Value = DateTime.Today.AddDays(-10);
cmd.Parameters.Add("dTo",OleDbType.Date).Value = DateTime.Today;
With SqlProvider you can also use named parameters.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform