Why does a user have to enter "Profile" data to enter data into other tables?
Posted
by
Greg McNulty
on Stack Overflow
See other posts from Stack Overflow
or by Greg McNulty
Published on 2011-01-09T01:08:54Z
Indexed on
2011/01/09
1:53 UTC
Read the original article
Hit count: 575
EDIT
It appears the user has to enter some data for his profile, otherwise I get this error below. I guess if there is no profile data, the user can not continue to enter data in other tables by default? I do not want to make entering user profile data a requirement to use the rest of the sites functionality, how can I get around this?
Currently I have been testing everything with the same user and everything has been working fine.
However, when I created a new user for the very first time and tried to enter data into my custom table, I get the following error.
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_UserData_aspnet_Profile". The conflict occurred in database "C:\ISTATE\APP_DATA\ASPNETDB.MDF", table "dbo.aspnet_Profile", column 'UserId'. The statement has been terminated.
Not sure why I am getting this error. I have the user controls set up in ASP.NET 3.5 however all I am using is my own table or at least that I am aware of.
I have a custom UserData
table that includes the columns:
id, UserProfileID, CL, LL, SL, DateTime
(id is the auto incremented int) The intent is that all users will add their data in this table and as I mentioned above it has been working fine for my original first user I created. However, when i created a new user I am getting this problem.
Here is the code that updates the database.
protected void Button1_Click(object sender, EventArgs e)
{
//connect to database
MySqlConnection database = new MySqlConnection();
database.CreateConn();
//create command object
Command = new SqlCommand(queryString, database.Connection);
//add parameters. used to prevent sql injection
Command.Parameters.Add("@UID", SqlDbType.UniqueIdentifier);
Command.Parameters["@UID"].Value = Membership.GetUser().ProviderUserKey;
Command.Parameters.Add("@CL", SqlDbType.Int);
Command.Parameters["@CL"].Value = InCL.Text;
Command.Parameters.Add("@LL", SqlDbType.Int);
Command.Parameters["@LL"].Value = InLL.Text;
Command.Parameters.Add("@SL", SqlDbType.Int);
Command.Parameters["@SL"].Value = InSL.Text;
Command.ExecuteNonQuery();
}
Source Error:
Line 84:
Command.ExecuteNonQuery();
© Stack Overflow or respective owner