I have a table which links to another table in the ASP.NET membership schema.
Problem is, all the PKs for the ASP.NET tables are uniqueidentifier so mine has to be too. When I add a SqlDatasource and call its Insert() method, I get the following error:
Cannot insert the value NULL into column ‘DiscountCode’, table ‘CreamDb.dbo.CustomInfo1’; column does not allow nulls. INSERT fails. The statement has been terminated.
The uniqueidentifier is also treated as an object (its data type), but there is no Guid data type. I had this problem before, but the schema was much simpler so I could fix it.
How can I go about fixing this? If I get rid of the data type part in the markup (so just leave the field/parameter name but not the data type stuff), I get another error so that is not possible.
Thanks
What do you mean by ‘there is no Guid data type’? What’s wrong with
System.Guid? Can’t you just useGuid.NewGuid(), set the field appropriately, and do the insert?EDIT: Just to give a bit more meat: attach an event handler to the Inserting event, and populate the field then, via the
DbCommandreturned bySqlDataSourceCommandEventArgs.Command. Or change the SQL used by the INSERT command to ask the database to populate the GUID field for you.