Link to home
Start Free TrialLog in
Avatar of saturation
saturation

asked on

ASP.NET SQL insert error with primary key field

I am using an InsertCommand to insert into my data table, but when the form gets submitted, I get the following error:

"System.Data.SqlClient.SqlException: Implicit conversion from data type sql_variant to uniqueidentifier is not allowed. Use the CONVERT function to run this query." -- The pers_personid field below is type "UniqueIdentifier" and is set as the primary key.  

My InsertCommand:

InsertCommand="INSERT INTO [tblDCPersonTest] ([pers_firstname], [pers_middlename], [pers_lastname], [pers_ssn], [pers_dob], [pers_phonehome], [pers_phonework], [pers_personid]) VALUES (@pers_firstname, @pers_middlename, @pers_lastname, @pers_ssn, @pers_dob, @pers_phonehome, @pers_phonework, @pers_personid)"



How do I fix this?
SOLUTION
Avatar of cyberkiwi
cyberkiwi
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of saturation
saturation

ASKER

Ok, did that.   Now I get

System.Data.SqlClient.SqlException: Cannot insert the value NULL into column 'pers_personid', table 'tblDCPersonTest'; column does not allow nulls. INSERT fails.

Did I set my primary key to be the wrong data type?   I just want it to start at 1 and increment automatically when a record is inserted.  
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial