Getting SQL Code from Datasource Query

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm using an SQL Command to read and update a datasource (in Access) and
would like to get the actual SQL return code from the query to provide better
feedback about any problems that might occur.

Is there a property or method that returns this code?
 
AFAIK, you cannot use the SqlCommand object with an Access database.
Apart from that, the CommandText property of any of the command objects
should give you the actual sql if the CommandType is Text.

hope that helps..
Imran.
 
mh1mark said:
I'm using an SQL Command to read and update a datasource (in Access) and
would like to get the actual SQL return code from the query to provide better
feedback about any problems that might occur.

Is there a property or method that returns this code?

Depending on what you mean be "return code", it may or may not be
possible to do what you're asking.

If you want the return value *you* specify in the SQL data, I don't kno
exactly how to do this in in Access. For SQL Server stored procedures,
you add a parameter named RETURN_VALUE, with
ParameterDirection.ReturnValue. After running the SqlCommand,
Parameters["RETURN_VALUE"].Value can be read to get the return code. If
recent versions of Access behave the same way (which they might, since
it's now the same database engine underneath) that should work as well.

If you want the *error code* generated by SQL, then you should catch any
SqlException exceptions thrown by your SqlCommand. the
SqlException.Errors collection contains one or more SqlError objects,
which includes all of the low-level SQL information included in the
error(s).

--Mike
 
Back
Top