Thread View: borland.public.cppbuilder.database.ado
6 messages
6 total messages
Started by Stephen Craig
Thu, 19 May 2005 04:58
Setting Query Parameters to a NULL string
Author: Stephen Craig
Date: Thu, 19 May 2005 04:58
Date: Thu, 19 May 2005 04:58
19 lines
1457 bytes
1457 bytes
Hi
I'm "playing" with an Access DB and am having problems setting query
Parameters to a String when the string is a empty.
eg
for the query
INSERT INTO myTable (MyField, field2) VALUES (:MyField, :field2)
If I set the parameter ...
qry->Parameters->ParamByName("MyField")->Value = "";
I get this error when I ExecSQL() "...Invalid Precision Value"
If I set the field without using parameters then all is Ok ie ...
INSERT INTO myTable (MyField, field2) VALUES ("", "some text")
Can I use Parameters when the fields may be Null strings?
Thanks
Steve
Re: Setting Query Parameters to a NULL string
Author: Ondrej Gratz
Date: Wed, 25 May 2005 15:11
Date: Wed, 25 May 2005 15:11
30 lines
1863 bytes
1863 bytes
Enclose string parameters in quotation marks...
INSERT INTO myTable (MyField, field2) VALUES (":MyField", ":field2")
Sincerely
Ondrej Gratz
Stephen Craig wrote:
> Hi
> I'm "playing" with an Access DB and am having problems setting query
> Parameters to a String when the string is a empty.
>
> eg
> for the query
> INSERT INTO myTable (MyField, field2) VALUES (:MyField, :field2)
>
> If I set the parameter ...
> qry->Parameters->ParamByName("MyField")->Value = "";
> I get this error when I ExecSQL() "...Invalid Precision Value"
>
> If I set the field without using parameters then all is Ok ie ...
> INSERT INTO myTable (MyField, field2) VALUES ("", "some text")
>
> Can I use Parameters when the fields may be Null strings?
>
> Thanks
> Steve
>
>
>
Re: Setting Query Parameters to a NULL string
Author: Stephen Craig
Date: Fri, 27 May 2005 00:37
Date: Fri, 27 May 2005 00:37
46 lines
2640 bytes
2640 bytes
Hi Ondrej,
Thanks for the reply
If I use quotes as you described (either single or double (\")) as follows
INSERT INTO myTable (MyField, field2) VALUES (':MyField', ':field2')
and I attempt to set parameters using
qry->Parameters->ParamByName("MyField")->Value = "";
Then I get the error
Parameter 'MyField' not found
Interestingly, if I revert back to
INSERT INTO myTable (MyField, field2) VALUES (:MyField, :field2)
and set the parameter to some string and then set it to a NULL then it all
is ok. ie...
qry->Parameters->ParamByName("MyField")->Value = "dummy";
qry->Parameters->ParamByName("MyField")->Value = "";
This works perfectly
I can only imagine that the first assignment is setting some parameter
property. Initially I thought that this would be the DataType property.
But setting this to ftString prior to the NULL assignment ie...
qry->Parameters->ParamByName("MyField")->DataType = ftString;
qry->Parameters->ParamByName("MyField")->Value = "";
makes no difference. I get the same old exception ...
[Microsoft][ODBC Microsoft Access Driver]Invalid precision value.
I also tried setting the parameter Attributes to paNullable
qry->Parameters->ParamByName("MyField")->Attributes << paNullable;
Still get exception
I think I'll just have to use the dummy assignment, unless anyone can come
up with a better answer
Steve
"Ondrej Gratz" <gratzo@atlas.cz> wrote in message
news:4294958b@newsgroups.borland.com...
> Enclose string parameters in quotation marks...
>
> INSERT INTO myTable (MyField, field2) VALUES (":MyField", ":field2")
>
> Sincerely
> Ondrej Gratz
>
Re: Setting Query Parameters to a NULL string
Author: Ondrej Gratz
Date: Fri, 27 May 2005 05:51
Date: Fri, 27 May 2005 05:51
64 lines
3448 bytes
3448 bytes
Hi Stephen,
I'm sorry, I didn't try it. Now I remember...some time ago "Parameter
'MyField' not found" exception has been the reason why I use
StringReplace function :-) instead of parameters.
I recommended quotes because I thought the SQL commmand would be wrong
when you used NULL values ...INSERT INTO myTable (MyField, field2)
VALUES (, )
I hope someone will give us better answer too.
Sincerely
Ondrej Gratz
Stephen Craig wrote:
> Hi Ondrej,
> Thanks for the reply
>
> If I use quotes as you described (either single or double (\")) as follows
> INSERT INTO myTable (MyField, field2) VALUES (':MyField', ':field2')
> and I attempt to set parameters using
> qry->Parameters->ParamByName("MyField")->Value = "";
> Then I get the error
> Parameter 'MyField' not found
>
> Interestingly, if I revert back to
>
> INSERT INTO myTable (MyField, field2) VALUES (:MyField, :field2)
> and set the parameter to some string and then set it to a NULL then it all
> is ok. ie...
> qry->Parameters->ParamByName("MyField")->Value = "dummy";
> qry->Parameters->ParamByName("MyField")->Value = "";
> This works perfectly
>
> I can only imagine that the first assignment is setting some parameter
> property. Initially I thought that this would be the DataType property.
> But setting this to ftString prior to the NULL assignment ie...
> qry->Parameters->ParamByName("MyField")->DataType = ftString;
>
> qry->Parameters->ParamByName("MyField")->Value = "";
> makes no difference. I get the same old exception ...
> [Microsoft][ODBC Microsoft Access Driver]Invalid precision value.
>
> I also tried setting the parameter Attributes to paNullable
> qry->Parameters->ParamByName("MyField")->Attributes << paNullable;
> Still get exception
>
> I think I'll just have to use the dummy assignment, unless anyone can come
> up with a better answer
>
> Steve
>
> "Ondrej Gratz" <gratzo@atlas.cz> wrote in message
> news:4294958b@newsgroups.borland.com...
>
>>Enclose string parameters in quotation marks...
>>
>>INSERT INTO myTable (MyField, field2) VALUES (":MyField", ":field2")
>>
>>Sincerely
>>Ondrej Gratz
>>
>
>
>
Re: Setting Query Parameters to a NULL string
Author: Viatcheslav V. Vassiliev
Date: Fri, 27 May 2005 09:49
Date: Fri, 27 May 2005 09:49
66 lines
3495 bytes
3495 bytes
> [Microsoft][ODBC Microsoft Access Driver]Invalid precision value.
Switch to Jet OLEDB provider - it is native for Access and is better than
OLEDB provider for ODBC that you use now. Connection string is:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\mydb.mdb;
//------------------------------------------
Regards,
Vassiliev V. V.
http://www.managed-vcl.com - using .Net objects in Delphi for Win32 +
ADO.Net
http://www.oledbdirect.com - The fastest way to access MS SQL Server,
MS Jet (Access) and Interbase (through OLEDB)
"Stephen Craig" <stevecraig@ozemail.com.au> �������/�������� � ��������
���������: news:42966bb3$1@newsgroups.borland.com...
> Hi Ondrej,
> Thanks for the reply
>
> If I use quotes as you described (either single or double (\")) as follows
> INSERT INTO myTable (MyField, field2) VALUES (':MyField', ':field2')
> and I attempt to set parameters using
> qry->Parameters->ParamByName("MyField")->Value = "";
> Then I get the error
> Parameter 'MyField' not found
>
> Interestingly, if I revert back to
>
> INSERT INTO myTable (MyField, field2) VALUES (:MyField, :field2)
> and set the parameter to some string and then set it to a NULL then it all
> is ok. ie...
> qry->Parameters->ParamByName("MyField")->Value = "dummy";
> qry->Parameters->ParamByName("MyField")->Value = "";
> This works perfectly
>
> I can only imagine that the first assignment is setting some parameter
> property. Initially I thought that this would be the DataType property.
> But setting this to ftString prior to the NULL assignment ie...
> qry->Parameters->ParamByName("MyField")->DataType = ftString;
>
> qry->Parameters->ParamByName("MyField")->Value = "";
> makes no difference. I get the same old exception ...
> [Microsoft][ODBC Microsoft Access Driver]Invalid precision value.
>
> I also tried setting the parameter Attributes to paNullable
> qry->Parameters->ParamByName("MyField")->Attributes << paNullable;
> Still get exception
>
> I think I'll just have to use the dummy assignment, unless anyone can come
> up with a better answer
>
> Steve
>
> "Ondrej Gratz" <gratzo@atlas.cz> wrote in message
> news:4294958b@newsgroups.borland.com...
>> Enclose string parameters in quotation marks...
>>
>> INSERT INTO myTable (MyField, field2) VALUES (":MyField", ":field2")
>>
>> Sincerely
>> Ondrej Gratz
>>
>
>
Re: Setting Query Parameters to a NULL string
Author: Stephen Craig
Date: Sat, 28 May 2005 11:04
Date: Sat, 28 May 2005 11:04
18 lines
1735 bytes
1735 bytes
Thanks, That fixed it!!!! "Viatcheslav V. Vassiliev" <support@oledbdirect.com> wrote in message news:4296ed4a@newsgroups.borland.com... > > [Microsoft][ODBC Microsoft Access Driver]Invalid precision value. > > Switch to Jet OLEDB provider - it is native for Access and is better than > OLEDB provider for ODBC that you use now. Connection string is: > > Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\mydb.mdb; > > //------------------------------------------ > Regards, > Vassiliev V. V. > http://www.managed-vcl.com - using .Net objects in Delphi for Win32 + > ADO.Net > http://www.oledbdirect.com - The fastest way to access MS SQL Server, > MS Jet (Access) and Interbase (through OLEDB)
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads