Venkat_KL said:
Hi Dear Armin Zingler,
Initially you asked,
insert into test (id, value) values (17, "param2")
How do I get this sql?
Before I wrote:
"SQL sent to database when calling ExecuteNonquery will be:"
Yes, the mentioned SQL is the "SQL that is sent to the database", and I want
to know how I can "get this SQL". Thus, "this SQL" = "SQL sent to the
database". The "Insert into.." is only an example - or do you think I always
want to insert 17 and "param2"?
Now you are telling That is not you wanted, you wanted the command
object generated SQL.
Command Object will not generate any SQL, It will only execute what
ever SQL Syntax you give it to that.
With Declaring Parameters and adding them to Parameters collection
and addding it to the command object, You can not get the SQL Query
what you asked initially.
That is, I will copy and paste here
insert into test (id, value) values (17, "param2")
How do I get this sql?
Yes, "this sql". The "SQL sent to the database" as mentioned in the sentence
that you did not quote here again.
first of all it is not double quotes, it is single quotes for the
string or char values
like
insert into test (id, value) values (17, 'param2')
Both is possible. Single or double quotes. I've always used double quotes
without a problem. (Of course, doesn't matter when using parameters.)
TO GET THIS QUERY, I SHOWED YOU THE METHOD.
<quote>
if I use parameters with an OleDbCommand, the OleDbCommand builds the final
SQL string to be send to the database. How do I retrieve this SQL?
</quote>
Obviously, "this SQL" refers to the sentence before that also mentions the
"SQL string to be send to the database." Maybe you lost the context.
Thus, you did NOT show me how to get the "SQL that is send to the database".
What you showed me is: a way to build an SQL that is hopefully equal to the
one that is send to the database. That's *the* difference, and that's why I
first wrote that your answer is a little bit funny (BTW, with a smiley
added). I said it's funny because we have Parameters now and we don't have
to build the SQL on our own, but if I want to have a look at the SQL that is
send to the database, you told me I have to build it on my own. Just to
explain it.
Correct me If I am wrong, You want to log the SQL Queyries along
with what ever value user inputs right!!
Right, but logging is only an example. It should be possible in general to
get the SQL I send to a database.
Armin