Using AddOutParameter and the DAAB

G

Guest

Hi,

I'm running into an error while trying to get the output value of an
identity column. In my database, the identity column is of type 'bigint',
which is what seems to be causing the problem.

The DAAB syntax I'm using for adding in an output parameter is:

string storedProcName = "myInsertProcName";
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetStoredProcCommand(myInsertProcName);

//add Input parameters - works fine

db.AddOutParameter(cmd, "idColumn", DbType.Int64, ???);

As you can see from the line above, the ??? is where I hit my problem. The
API requires an 'int size' with the description being the max possible size
of the return value. I tested this issue with a dummy table, setting the
seed to int.maxvalue, and it does throw an exception, with an arithmetic
error. While I don't have this many records yet, I anticipate it in the
future.

I should probably mention it is an insert method, and I'm running
db.ExecuteNonQuery(cmd) against the database.

I looked around and couldn't find anyone else running into this problem, so
any help would be appreciated.

Thanks,
Pete
 
K

Kevin Yu [MSFT]

Hi Pete,

The last argument of AddOutParameter is a value for the size of the
parameter. It is the number of bytes, but not max value you might input.
Since it is an Int64 value, it is 64 bits long, and thus is 8 bytes long.
So use 8 as the size value.

db.AddOutParameter(cmd, "idColumn", DbType.Int64, 8);

HTH.

Kevin Yu
Microsoft Online Community Support

============================================================================
==========================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
============================================================================
==========================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
G

Guest

Thanks Kevin. I was able to test it today, and it worked just fine. I
appreciate the quick response.

-Pete
 
K

Kevin Yu [MSFT]

You're welcome, Pete. It was nice to know that you have had the problem
resolved. Thanks for sharing your experience with all the people here. If
you have any questions, please feel free to post them in the community.

Kevin Yu
Microsoft Online Community Support

============================================================================
==========================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
============================================================================
==========================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top