Pass uniqueidentifier to stored procedure

X

xanthviper

Hey there,

I've been looking around for awhile now on how to do this and haven't
been able to really find a clear answer.

I have a stored procedure that inserts a new entry into a SQL 2000
table. The Stored Procedure(SP) accepts an ID that has been declared
as a UNIQUEIDENTIFIER in the SP, as well as in the Table (as primary
key).

I generate a GUID in my C# ASP.NET app and treat it as a string. In
passing it to the SP, I have the data type set to
SqlDbType.UNIQUEIDENTIFIER. Of course when running the function, I get
a problem stating I cannot cast a string to a uniqueidentifier. So in
order to solve this, I have set up the SP ID parameter to be
SqlDbType.Char, 37. This works fine. However, something tells me this
really isn't the proper way to do this. Could someone perhaps give me
the guidance as to what the proper way is to pass a uniqueidentifier to
stored procedure?

Thank you for your time.
 
W

W.G. Ryan eMVP

Check the thread from yesterday
error with unique identifier and sql data provider
 
X

xanthviper

Ahh..that was it:

parameters[0].Value = new System.Guid(docID);

Thank you very much. I appreciate it.
 

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