Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8026677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:34:08+00:00 2026-06-04T23:34:08+00:00

i am trying to use a parameterized query with Delphi TADOCommand: var s: WideString;

  • 0

i am trying to use a parameterized query with Delphi TADOCommand:

var 
   s: WideString;
   cmd: TADOCommand;  
   recordsAffected: OleVariant;
begin
   cmd := TADOCommand.Create(nil);
   cmd.Connection := Connection;
   cmd.CommandText := 'INSERT INTO Sqm(Filename) VALUES(:filename)';

   s := AFilename;
   cmd.Parameters.ParamByName('filename').Value := s;
   cmd.Execute();

The resulting data in the database is complete mangled:

C?:\U?s?er?s?\i??n?.A?V`A?T?O?P?I?A?\A?p?p?D??t??\L?o???l?\A?v?at??r? S?o?f?t?w?är¨? C?r??t?i??n?s?\S?o°f?t?w?r?? Q?u??li?t?y? M??t?r?i?cs?\C??S?-s?q?m?00.x?m?l


i can use a native parameterized ADO Command object. It saves the data correctly:

C̬:\Ȗŝḙr͇s̶\i̜ẵn̥.ÀV̹AͧT̶O̠P̩I̿Ȁ\A͜p̥p̔D͑ẫt̒ā\L̫o͋ɕălͭ\A̼v̼ẵt͈ấr̄ S̫o̖f͎t̻w̵ạr͂ẽ C̾r̮ḛẵt͘iͩo̳n̬s̨\S̪ōf̒t͘w̚âr̿ɇ Qͬüẳlͮi̫tͥy̽ M͘ȇt̨r̟i̻çš\C͍MͥS̚-s̞q̕m͜00.xͤm̧l̝

but it’s very fragile and not suitable for production use.

How can i use unicode/WideStrings with TADOCommand in Delphi?

Bonus Chatter

In SQL Server Profiler you can see the SQL being executed:

exec sp_executesql N’INSERT INTO Sqm(Filename) VALUES(@P1)’, N’@P1 char(300),@P2 text’, ‘C?:\Us?er?s?\i?än?.A?V?A?T?O?P?I?À\A?p?p?D?ât?a\L?o?çal¯\A?v?at??r? So?f?t?w?ar?? C?r??á?i?o?n?s?\So¸f”t?w?ar?? Q?u??l?i?ty? M??t?r?i¸?s`\C?M°S?-s?q?m?00.?m¨´l¯ ‘

Which points out the problem – it’s building the WideString parameter as a char(300) value. Make it not broke.

The last i see of my WideString before it goes down the parameter hole is:

ParameterObject.Value := NewValue;

where

  • NewValue is a variant of type VT_BSTR (aka varOleStr) with the proper value
  • ParameterObject is a native ADO _Parameter object, with a .Type of 129 (adChar)

Even trying to force the parameter type:

cmd.Parameters.ParamByName('filename').DataType := ftWideString;
cmd.Parameters.ParamByName('filename').Value := s;

doesn’t help.

Note: This question is part of a series on how to paramaterize INSERT INTO foo (value) VALUES (%s)

  • https://stackoverflow.com/questions/10726212/using-wrong-type-with-parameterized-query-causes-error
  • How big is an nvarchar(max) as far as ADO is concerned?
  • How to parameterize widestrings using TADOCommand parameterized query?
  • "Must declare the variable @myvariable" error with ADO parameterized query
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T23:34:09+00:00Added an answer on June 4, 2026 at 11:34 pm

    The answer is that it cannot be done in Delphi (5).

    It might be fixed in newer versions of Delphi; but without anyone to test it we won’t know.

    Q.: How to parameterize widestrings using TADOCommand parameterized query?
    A.: You can’t. Sorry for the inconvience.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was trying to to use parameterized query with data reader when I get
I'm trying to update data. Whenever I use a parameterized query it gives me
Trying to use GnuPG with Delphi (Win32). I need to sign some file with
I am trying to use Properties file to parameterize connection to Mongodb. I have
I'm trying to switch some hard-coded queries to use parameterized inputs, but I've run
I'm trying to use one of the simplest forms of reflection to create an
Im trying to perform a parameterized query in SQLite from C#, and the method
I was trying use a set of filter functions to run the appropriate routine,
I'm trying use self-signed certificate (c#): X509Certificate2 cert = new X509Certificate2( Server.MapPath(~/App_Data/myhost.pfx), pass); on
I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.