Failed to convert parameter value from a Int32 to a Guid.

agroom

Active member
Joined
Sep 14, 2006
Messages
39
Programming Experience
Beginner
I get this error when trying to save to my table.

The dataset I'm using has the primary key auto increment, but the data type always switches to System.Int32. I've tried several data types in my MDB but every time I get this error:

"Failed to convert parameter value from a Int32 to a Guid."

If I switch the data type in my dataset to Guid, then it turns auto increment off.
 
It's impossible to convert those 2 types of data. Integers and GUID's or Global Unique Identifiers are totally different. GUID is a 16-byte (128-bit) number. Usually represented in Hexidecimal like 3F2504E0-4F89-11D3-9A0C-0305E82C3301. Which ever way you choose you will have to keep it the same throughout your program.

The current implementation of GUIDs on SQL Server 2000 use the NEWID() function that generates values that are "random". In SQL Server 2005, we're suppose to be given a function that will create GUID's that are sequential increasing. I haven't looked into it though, but the chances of two GUID's matching are very slim.
 
Okay, my next question then is what would I need to do in order to setup my application to auto generate a new primary key? It looks like the easiest thing is to do it though my dataset having it auto increment when a new row is added to the table, but then I still run into the conversion problem.
 
I would let the database generate the ID value for you. That functionality is already built in. About the conversion problem, what field type are you storing in your database? Are you using the built in membership roles? If so they do use a GUID field for the identifer.
 
I know how to auto increment using an SQL statement when creating the table, but I created it in the VS2005 designer so I'm not sure how it's done from there. Any help with this is greatly appreciated!
 
About the conversion problem, what field type are you storing in your database? Are you using the built in membership roles?

I'm pretty new to this, so let me make sure I understand what you're talking about. By saying built in membership roles, are you asking if I'm using the pre-set data types in the designer? If so, then yes, I've assigned my key field type Int.

If so they do use a GUID field for the identifer.

So does this mean by making a field the primary key, it's automatically type GUID?
 
I know how to auto increment using an SQL statement when creating the table, but I created it in the VS2005 designer so I'm not sure how it's done from there. Any help with this is greatly appreciated!

Played around with this a little more and found the auto increment settings. I wrote some test data in the designer and it auto incremented, so everything looks good on for that.

However, when I run my application now, I get the error "Column "identifier" does not allow nulls." How would I get around this since the database is going to assign the value upon saving the row to the database?

Thanks for the help with this issue!
 
By saying built in membership roles, are you asking if I'm using the pre-set data types in the designer?

Sorry to confuse you with that. I didn't know if you were creating a web or win app. In ASP.Net 2.0 MS has included a membership service that provides a framework for managing user accounts. The framework is composed of a membership class with a set of methods that can be used to create, delete, modify, retrieve, and authenticate users. In the database it uses type GUID field to identify the user.

So does this mean by making a field the primary key, it's automatically type GUID?

No, you can set primary key on other types, just 1 primary key per table. Check out this definition of a primary key... http://databases.about.com/cs/administration/g/primarykey.htm

I would search the web for some tutorials on database design. There is a wealth of info out there.
 
Back
Top