>>>>Now, having done that, is there an easy way to get the new ID that was generated for this new record?
>>>
>>>You can do SELECT MAX(iID)....but it is not a good idea in a multi-user environment. The best thing is to pre-fetch the iId.
>>>
>>
>>Any idea on how to do that (pre-fetch the key)? In this particular case, I've got a candidate key I could use to requery the table w/and grab it, but I know in most cases I won't.
>
>You can use SqlCommand.ExecuteScalar() funtion which is optimized to return single value from the database. You should be able to call NewId() SP straight through SqlCommand.
>
>Let me know if you need code examples...
Yeah, code examples (for calling NewID() directly) would be appreciated. I was able to call NewID():
oleCmd.CommandText = "NewID('user')";
oleCmd.ExecuteNonQuery();
However, I wasn't able to get the return value. I tried using the parameter object:
oleCmd.CommandText = "NewID('user')";
oleParameters = oleCmd.Parameters.Add("user_iid", System.Data.OleDb.OleDbType.Integer);
oleParameters.Direction = System.Data.ParameterDirection.ReturnValue;
oleParameters.Value = 0;
oleCmd.ExecuteNonQuery();
string newUserIID = oleCmd.Parameters["user_iid"].Value.ToString() ;
But, all I keep getting back is "0".