BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

NULL Parameters in TADOQuery

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder Databases (ADO)
View previous topic :: View next topic  
Author Message
Ruben Lopez
Guest





PostPosted: Mon Nov 20, 2006 10:05 pm    Post subject: NULL Parameters in TADOQuery Reply with quote



Hi to all!

I need send a sqlquery using the TADOQuery. I use the next metod.

//****************************************************
TADOQuery *q=new TADOQuery(NULL);
q->Connection = this->ADOConnection1;//Conected OK
q->SQL->Clear();
q->SQL->Add("INSERT INTO Table Values(:Filed_Id,:Name1,:Value1)");
q->Parameters->Clear();
q->Parameters->ParseSQL(q->SQL->Text,true);
q->Parameters->Items[0] = 1;
q->Parameters->Items[1] = NULL; //I test q->Parameters->Items[1] = "";
q->Parameters->Items[2] = NULL;
try
{
q->ExecSQL();
}
catch(Exception *e)
{
Application->ShowException(e);
}


Name1 it's a NVARCHAR(255) value whit IS NULL option.
Value1 it's an Integer value whit IS NULL option.

The problem is in the Patameter[Name1], when put the parameter to NULL,
raise an Exception, if put a value like " " it's all right.

The exception It's in Spanish and I try to Traduce it:


Not this allowed to the implicit conversion of the data type TEXT to the
data type NVARCHAR.Use the Function CONVERT TO EXECUTE THIS query.



How I can put this value to null;
Back to top
Clayton Arends
Guest





PostPosted: Mon Nov 20, 2006 10:44 pm    Post subject: Re: NULL Parameters in TADOQuery Reply with quote



Items[] returns an object of type TParameter. Setting that to NULL is not
what you want to do. You want to access the properties of the returned
object. Try this instead:

q->Parameters->Items[0]->Value = 1;
q->Parameters->Items[1]->Value = NULL;
q->Parameters->Items[2]->Value = NULL;

In some cases you might have to set the type of the parameter correctly:

q->Parameters->Items[1]->DataType = ftString; // for example

Also, this isn't part of your problem but take a look at your following
code:

Quote:
q->Parameters->Clear();
q->Parameters->ParseSQL(q->SQL->Text,true);

If ParamCheck is set to true for the query "q" (which it is by default) then
this code is already being performed when q->SQL is set. There is no need
to do it twice.

HTH,
- Clayton
Back to top
Ruben Lopez
Guest





PostPosted: Tue Nov 21, 2006 6:10 pm    Post subject: Re: NULL Parameters in TADOQuery Reply with quote



Thanks for your reply.

And excuse me. I put the Property->Items[]->Value in mi source code but
I forgot put the "->Value" in the question.

The problen it's that I can't put a NULL value in a property.
If I put NULL in a Integer value, it is converted to 0.

The q->Parameters->ParseSQL(q->SQL->Text,true); works fine, create all
of the params for the q->SQLText query.

Thanks again.

Clayton Arends escribió:
Quote:
Items[] returns an object of type TParameter. Setting that to NULL is not
what you want to do. You want to access the properties of the returned
object. Try this instead:

q->Parameters->Items[0]->Value = 1;
q->Parameters->Items[1]->Value = NULL;
q->Parameters->Items[2]->Value = NULL;

In some cases you might have to set the type of the parameter correctly:

q->Parameters->Items[1]->DataType = ftString; // for example

Also, this isn't part of your problem but take a look at your following
code:

q->Parameters->Clear();
q->Parameters->ParseSQL(q->SQL->Text,true);

If ParamCheck is set to true for the query "q" (which it is by default) then
this code is already being performed when q->SQL is set. There is no need
to do it twice.

HTH,
- Clayton

Back to top
Clayton Arends
Guest





PostPosted: Wed Nov 22, 2006 5:03 am    Post subject: Re: NULL Parameters in TADOQuery Reply with quote

Quote:
The problen it's that I can't put a NULL value in a property.
If I put NULL in a Integer value, it is converted to 0.

I made the same mistake in my post. Use "Null()" rather than "NULL".

Quote:
The q->Parameters->ParseSQL(q->SQL->Text,true); works fine, create all of
the params for the q->SQLText query.

Maybe so, but I was trying to point out that this is done by default when
you alter the SQL property. Remove the call to ParseSQL() and you will see
that your code will execute the same.

- Clayton
Back to top
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder Databases (ADO) All times are GMT
Page 1 of 1

 
 


Powered by phpBB © 2001, 2006 phpBB Group
.