Error: "Characters found after end of SQL Statement"

I'm using Delphi 6 and ADO to get into an Access table using an ADOQuery.

The code is:

with ADOQuery1.SQL do begin
  Clear;
  Add('SELECT DISTINCT dbo_Worksheets.Codes FROM dbo_Worksheets WHERE Work_Date >= :Params1');
  Add(' AND Work_Date <= :Params2');
  ADOQuery1.Parameters[0].Value := wwDBDateTimePicker1.Date;
  ADOQuery1.Parameters[1].Value := wwDBDateTimePicker2.Date;
end;
ADOQuery1.Open;

At run time, on opening the query, the error occurs.  Any thoughts?
0
Chris
1/8/2009 10:44:43 PM
embarcadero.delphi.ado 597 articles. 1 followers. Follow

8 Replies
894 Views

Similar Articles

[PageSpeed] 47

Try specifying the parameter datatype before asigning a value to the parameter.

AOQuery1.Parameters[0].dataType := ftDateTime;

> {quote:title=Chris Brockway wrote:}{quote}
> I'm using Delphi 6 and ADO to get into an Access table using an ADOQuery.
> 
> The code is:
> 
> with ADOQuery1.SQL do begin
>   Clear;
>   Add('SELECT DISTINCT dbo_Worksheets.Codes FROM dbo_Worksheets WHERE Work_Date >= :Params1');
>   Add(' AND Work_Date <= :Params2');
>   ADOQuery1.Parameters[0].Value := wwDBDateTimePicker1.Date;
>   ADOQuery1.Parameters[1].Value := wwDBDateTimePicker2.Date;
> end;
> ADOQuery1.Open;
> 
> At run time, on opening the query, the error occurs.  Any thoughts?
0
Brian
1/9/2009 12:27:19 AM
"Chris Brockway" wrote in message news:64787@forums.codegear.com...
>  ADOQuery1.Parameters[0].Value := wwDBDateTimePicker1.Date;
>  ADOQuery1.Parameters[1].Value := wwDBDateTimePicker2.Date;


The Value property is a variant and they do not get along with datetimes 
well. Use:

  ADOQuery1.Parameters[1].AsDateTime := wwDBDateTimePicker2.Date;

-- 
Wayne Niddery - TeamB (www.teamb.com)
Tips to Get Published: http://dn.codegear.com/article/38467
Winwright, Inc. (www.winwright.ca)
0
Wayne
1/9/2009 12:38:15 AM
> {quote:title=Wayne Niddery wrote:}{quote}
> "Chris Brockway" wrote in message news:64787@forums.codegear.com...
> >  ADOQuery1.Parameters[0].Value := wwDBDateTimePicker1.Date;
> >  ADOQuery1.Parameters[1].Value := wwDBDateTimePicker2.Date;
> 
> 
> The Value property is a variant and they do not get along with datetimes 
> well. Use:
> 
>   ADOQuery1.Parameters[1].AsDateTime := wwDBDateTimePicker2.Date;
> 
> -- 
> Wayne Niddery - TeamB (www.teamb.com)
> Tips to Get Published: http://dn.codegear.com/article/38467
> Winwright, Inc. (www.winwright.ca)

ADOQuery1.Parameters[1].AsDateTime := wwDBDateTimePicker2.Date;  doesn't compile as the AsDateTime property is not included under my D6 enterprise edition.  I don't know if others do.

Brian's suggestion of 

ADOQuery1.Parameters[1].DateType := ftDateTime; does compile, but I'm still finding the same run time error, "Characters found after end of SQL statement".
0
Chris
1/9/2009 1:27:49 AM
Wayne Niddery wrote:

>   ADOQuery1.Parameters[1].AsDateTime :=
> wwDBDateTimePicker2.Date;

That will not work. ADO parameters only support .Value.

-- 
Bill Todd (TeamB)
0
Bill
1/9/2009 2:03:28 AM
Try this code :
ADOQuery1.Parameters[0].Value := FloatToStr(wwDBDateTimePicker1.Date)

Converting a datetime format to a string will give a result like "39683.125407+E00" but it works with SQL statement.

Another thing, I use FloatToStr in Delphi 2009, not D6. But if the function does not exist, you can use Str().
0
Nguyen
1/9/2009 9:33:59 AM
Chris Brockway wrote:

> with ADOQuery1.SQL do begin
>   Clear;
>   Add('SELECT DISTINCT dbo_Worksheets.Codes FROM dbo_Worksheets WHERE
> Work_Date >= :Params1');   Add(' AND Work_Date <= :Params2');
>   ADOQuery1.Parameters[0].Value := wwDBDateTimePicker1.Date;
>   ADOQuery1.Parameters[1].Value := wwDBDateTimePicker2.Date;
> end;
> ADOQuery1.Open;

I have D7 and MS Office 2003.  The following worked for me.

I dropped an ADOQuery on a form, along with an ADOConnection.  Set the
ADOConnection.String to use Jet 4.0 driver and a test db.  Set the
ADOQuery's connection to the ADOConnection component and ran the same
code with my test table.  No problems.


-- 
Iman
0
Iman
1/9/2009 4:45:51 PM
Iman Crawford wrote:
> I have D7 and MS Office 2003.  The following worked for me.

I forgot to add you should probably post more info.  What version of
Office, what does you connection string look like.

You could try building the SQL without params.  Make sure you quote the
date before adding it to the sql statement.


-- 
Iman
0
Iman
1/9/2009 4:52:30 PM
> {quote:title=Diep Thanh Nguyen wrote:}{quote}
> Try this code :
> ADOQuery1.Parameters[0].Value := FloatToStr(wwDBDateTimePicker1.Date)
> 
> Converting a datetime format to a string will give a result like "39683.125407+E00" but it works with SQL statement.
> 
> Another thing, I use FloatToStr in Delphi 2009, not D6. But if the function does not exist, you can use Str().

I was getting type mismatch errors with the FloatToStr() conversion.  Tried DateToStr() and that works well.
0
Chris
1/12/2009 5:08:58 AM
Reply:

Similar Artilces:

"The resource cannot be found." error when there is a "dot" at the end of the url
Hi,I'm using ASP .NET MVC Beta and I get the HTTP 404 (The resource cannot be found) error when I use this url which has a "dot" at the end:  http://localhost:81/Title/Edit/Code1.If I remove the dot at the end or the dot is somewhere in the middle I don't get the error. Error details are as follows:I tried to debug but it I get the error from "System.Web.CachedPathData.GetConfigPathData(String configPath)" before ProcessRequest in MvcHandler.Is "dot" not allowed at the end of a url? Or is there a way to fix the route definition to handle this url?Th...

Multiple "AND" and "OR" Statements in an SQL Query
Hello,  I've got a table called "plants" which, up-until-recently, was being searched by category using the following SQL (and using the CategoryID field): SELECT plants.Latin_Name, Size.ekm_ID, plants.Common_Name, plants.Short_Description, plants.Thumb_URL, plants.CategoryID, plants.ProductID, Size.Size, Size.Price, Size.MostPopular FROM plants INNER JOIN Size ON plants.CategoryID = Size.CategoryID AND plants.ProductID = Size.ProductID WHERE (plants.CategoryID = @CategoryID) AND (Size.MostPopular = 'True') AND (Size.Availability = 'True') ORDER BY plants.Latin_Name  I now want ...

" union " + " order by " sql statement?
hi, It has error message " column 'CAT' not found " , when i compiled in Interactive SQL ASA7. sorry, my english is poor. ======= what's wrong the sql statement as the below. SQL: select '' as CAT, 'ALL' as DES union select cat,des from category group by cat,des order by cat I want the result is : CAT DES ------- ------ ALL C Cat C B Cat B : : The component SELECT statements must each have the same number of items in the select list, and cannot con...

"Newline in constant" and "Too many characters in character literal" errors. Dataadapters and datatables.
I'm getting the above errors on line 41 (parameter delcaration)... been hitting my head on this for a while.. please help.  public static DataTable dtCleanVendorUsers(string username) {SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["VendorEvaluationConnectionString"].ConnectionString); SqlDataAdapter dataadapter = new SqlDataAdapter();dataadapter.SelectCommand = new SqlCommand("SELECT vendoruser_user_id, vendoruser_vendor_id, user_name, vendor_name, vendor_evaluated FROM vwVendorUsers WHERE (vendor_evaluated = 0) and (u...

SQL error: java.sql.SQLException: Column "-n/a-" not found
Good Morning, I am getting the above SQL error when I define a new variable in my select statement. This syntax did not generate an error message in the V9 beta release. Is this select syntax no longer permitted? Or am I missing some other issue? The error message occurs on new variables in the select regardless of the db element being the index. The error message ceases if I remove the "nextid" verbage from the select. Entire text of code and command winow output are below. Thanks much for your input, and thanks (belatedly) for your input on my previous post. Ca...

"End of Statement Expected" Error
Hello, I am creating a fairly basic Google Maps web form, but I keep getting a compiler error "End of Statement Expected".  At first, I had my VB code in a code-behind.  At that time, the error said it was happening on Line 1 or my aspx file (the page directive).  I then tried getting rid of the code-behind and moving my VB code to a script tag in the aspx file.  The error then moved to the ending </script> tag of the VB code, but still the same error.  Here is my code, any help is greatly appreciated:<%@ Page Language="VB" AutoEventWire...

"SQL Error: Error mapping failed" with Delphi 6 Application and DBExpress
Im using Delphi 6, Firebird 2.x, dbExpress The problem is only with remote database connection and not with local connection. The following connection gives and error Database := MyServer:C:\DEMO.FDB But when locally connected i.e database in the same computer Database := C:\FBdatabases\dbAccounts.FDB Following solution from Firebird forun worked ----------------------------------------- Actually, the issue is inside Borland's DBX driver for InterBase. It's not very much compatible with Firebird. First of all, it uses some internal (metadata) queries in the...

unbalanced "/" before "switch" statement cause fatal error
Hi, I was going to report this as a bug in Switch, after spending over an hour debugging why a script was failing compilation. Then I saw it was already reported... over a year ago :( http://rt.cpan.org/NoAuth/Bug.html?id=3D5607 Any chance of this being fixed? Thanks, -- Offer Kaye On 11/23/05, Offer Kaye wrote: > I was going to report this as a bug in Switch, after spending over an > hour debugging why a script was failing compilation. Then I saw it was > already reported... over a year ago :( > > http://rt.cpan.org/NoAuth/Bug.html?id=3D5607 > > Any...

"FIRST 10" or "TOP 10" for SQL statement?
To get the top 10 values in a table, is the proper syntax: SELECT FIRST 10 FROM... or is it: SELECT TOP 10 FROM... (MS SQL Server) ?Clay Shannon,author of historical works, novels, and art/poetryhttp://www.knowitallsports.com/booklinks.aspx Select Top 10.... Regards Mike [MVP - ASP/ASP.NET]My site...

SQL statement failed: (-305) I/O error Fatal error: A disk read from file "SomeDatabase.db" failed with error code: (38)
SQL Anywhere 10.0.1.3831 E. 2009-09-11 21:55:41. SQL statement failed: (-305) I/O error Fatal error: A disk read from file "D:\FHMSL\iFHMS\Data\Feedlot111.db" failed with error code: (38) -- transaction rolled back E. 2009-09-11 21:55:41. Error while executing hook procedure sp_hook_dbmlsync_end. Received this error while running a proc during sync. Tried to validate the db in Sybase Central resulting in the same error. I saw the post at http://groups.google.com/group/sybase.public.sqlanywhere.general/browse_thread/thread/b5d958904160e576?fwc=1 and am wondering if th...

"OUTPUT TO" Statement in "IF"
Hi All, I'm trying to execute the following statements: IF Condition THEN SELECT col FROM tbl; OUTPUT TO 'filename'; ELSE statements... END IF This gave me an error at 'SELECT' Can anyone tell me what is the correct approach? Thanks Stelios Stylianou > Hi All, > > I'm trying to execute the following statements: > IF Condition THEN > SELECT col FROM tbl; > OUTPUT TO 'filename'; > ELSE > statements... > END IF > > This gave me an error at 'SE...

SQL Server 2005 error: "Incorrect syntax near "-" "
Hello, I have an application written in visual basic which connects to a SQL Server 2005In DB of SQL Server I have many tables. Table names can contain chars like: "-",  "\",  ".", etc. When I execute the instruction in visual basic sTableName= "Table-3" ' or ""Table-3"" or "Table_1" or sTableName= """" + "Table_1" + """"   -> """" = 4 quates (2 for string identify and two for writing in string a quate chr(34)->" strQu...

What´s the purpose of "classifieds-categories.sql" "classifieds-add.sql""classifieds-remove.sql"?
 Hello all, what´s the purpose of the scripts I enunciated above on the classified starter kit?  "classifieds-categories.sql"  seems to create the initial parent categories, the others 2 names sugest they are used to add and remove ads, but i cant get how.There are 10 types of people in this world:Those who understand binary and those who don't. The classifieds starter kit is ready for upload right out of the box. Any .sql files you find in App_Data are scripts of the database.They are there to make it easy for uploading your site. So if you were not mak...

Getting Error: "End of statement expected"
Dear Forum,  First of all, thanks for all of your help in the past.I am getting the error: " End of Statement expected"  What do you think I am missing on this?    My code is below. Thanks again for all of your help, JeffBoise, ID  Compiler Error Message: BC30205: End of statement expected.Source Error: Line 43: Dim Email as Object = myCmd.ExecuteScalar() Line 44: Line 45: If Email IsNot Nothing andalso Email.ToString() = searchtext Line 46: Then Line 47: alreadydiv.Visible = True   <%@ Page Explicit = "T...

Web resources about - Error: "Characters found after end of SQL Statement" - embarcadero.delphi.ado

Resources last updated: 11/26/2015 5:40:35 PM