Page 1 of 1

SQLInsert

Posted: Mon 01 Sep 2008 14:30
by joegoh
Can you an example of how to use parameterized input with MyQuery1?
Can you illustrated?

Posted: Wed 03 Sep 2008 13:59
by Dimon
The example of a code for inserting record in a table:

Code: Select all

MyQuery.SQL.Text := 'INSERT INTO table_name(field1) VALUES(:field1)';
MyQuery.ParamByName('field1').AsInteger := 1;
MyQuery.Execute;

Posted: Tue 14 Oct 2008 04:36
by JustAnEngineer
Hi,

I'm trying to do something quite similar, but and only getting two bytes stored, which apparently are the #13#10 at the beginning of the text data (coming out of a TStrings.Text).

The table I'm posting to has about 30 fields. Everything in the table is posting fine given the example above with the exception of one field.

The field I'm having a problem with is this:

MyHtmlField [Text, NULL]

I do the following:

Code: Select all

MyQuery.SQL.Text := 'INSERT INTO table_name(MyHtmlField) VALUES(:MyHtmlField)';
MyQuery.ParamByName('MyHtmlField').AsString := tsHTML.Text;
MyQuery.Execute;
Like I mentioned above, it's just storing two bytes. That is all. I've also tried just using a TMySqlTable and doing the regular Append...AsString...Post

Should I be escaping something? Or is there a better way to put text into a Text field? Also, I'm doing this at run-time. I'm not creating the component on a form or anything. I have the Server in the DataModule, but creating the queries at run-time.

Thanks,

Wes

Posted: Tue 14 Oct 2008 04:43
by JustAnEngineer
:oops:

Forget the question. It was my fault. Your components are flawless and great!

Long Live DevArt!!

Wes