You are not logged in.
Pages: 1
Error occured on execute prepared statement with NULL parameter using SQLOLEDB provider.
With SQLNCLI10 provider following code work properly.
program Project1;
{$APPTYPE CONSOLE}
uses
SysUtils, SynCommons, SynDB, SynOleDb;
var
cp: TSQLDBConnectionProperties;
begin
try
cp := TOleDBMSSQLConnectionProperties.Create('.\sqlexpress', 'master', '', '');
try
cp.ExecuteNoResult(StringToUTF8('if OBJECT_ID(''MyTable'', ''U'') is null create table MyTable (col1 nvarchar(10))'), []);
with cp.MainConnection.NewStatement do try
Prepare(StringToUTF8('insert into MyTable(col1) values (?)'), False);
BindNull(1);
ExecutePrepared; // <-- ERROR RAISE HERE
finally
Free;
end;
//cp.ExecuteNoResult(StringToUTF8('if OBJECT_ID(''MyTable'', ''U'') is not null drop table MyTable'), []);
finally
cp.Free;
end;
except
On E: Exception do
Writeln(2, E.Message);
end;
end.
Error message:
EOleDBException with message 'OLEDB Error 80040E14 - (line 1): Must declare the scalar variable "@P1". (line 1): Incorrect syntax near ')'.
Pages: 1