Please Help me :(
-
Hi, 2 tables. User table and Request Table. Request table has a foriegn key in the Request table called AssignedToID. I would like to store a Request record without specifying the AssignedToID. I am receiving the following error: INSERT statement conflicted with COLUMN FOREIGN KEY constraint 'FK_tblRequest_tblUser1'. The conflict occurred in database 'PMSystem', table 'tblUser', column 'inUserID'. The input for AssignedToID is a Dropdown List. Here's how it is bound:
lst2.Text = "None" lst2.Value = 0 lst2.Selected = True sQueryDDL = "SELECT tblUser.inUserID, tblUser.vchSurname + ', ' + tblUser.vchForename AS AssignedToName FROM tblUser ORDER BY tblUser.vchSurname" sTableDDL = "tblUser" dsDDL = clsCommon.getData(sQueryDDL, sTableDDL) dsDDL.Tables(0).DefaultView.Sort = "AssignedToName" Me.ddlAssignedToID.DataSource = dsDDL.Tables(0).DefaultView Me.ddlAssignedToID.DataTextField = "AssignedToName" Me.ddlAssignedToID.DataValueField = "inUserID" Me.ddlAssignedToID.DataBind() Me.ddlAssignedToID.Items.Insert(0, "lst2")
The AssignedToID field is not mandatory and if a user does not select anything, the default value to be stored is 0. The compiler is not liking this. What could be wrong? Thank you in advance. -
Hi, 2 tables. User table and Request Table. Request table has a foriegn key in the Request table called AssignedToID. I would like to store a Request record without specifying the AssignedToID. I am receiving the following error: INSERT statement conflicted with COLUMN FOREIGN KEY constraint 'FK_tblRequest_tblUser1'. The conflict occurred in database 'PMSystem', table 'tblUser', column 'inUserID'. The input for AssignedToID is a Dropdown List. Here's how it is bound:
lst2.Text = "None" lst2.Value = 0 lst2.Selected = True sQueryDDL = "SELECT tblUser.inUserID, tblUser.vchSurname + ', ' + tblUser.vchForename AS AssignedToName FROM tblUser ORDER BY tblUser.vchSurname" sTableDDL = "tblUser" dsDDL = clsCommon.getData(sQueryDDL, sTableDDL) dsDDL.Tables(0).DefaultView.Sort = "AssignedToName" Me.ddlAssignedToID.DataSource = dsDDL.Tables(0).DefaultView Me.ddlAssignedToID.DataTextField = "AssignedToName" Me.ddlAssignedToID.DataValueField = "inUserID" Me.ddlAssignedToID.DataBind() Me.ddlAssignedToID.Items.Insert(0, "lst2")
The AssignedToID field is not mandatory and if a user does not select anything, the default value to be stored is 0. The compiler is not liking this. What could be wrong? Thank you in advance.It looks like you are inserting a value into tblUser, but the Column inUserID needs to have the same value as what is going into tblUser.
-
It looks like you are inserting a value into tblUser, but the Column inUserID needs to have the same value as what is going into tblUser.
-
To be honest, I just want to leave the "AssignedTo" value as null, but it won't let me :(. If anyone has any suggestions, please help. Thank you for your reply mate.
Columns with constraints or keys can not have null values. You will need to either eliminate the constraint on the AssignedTo column or will have to provide the same value from the insert in both places. In the db if you run sp_help [TableName] you will see the constraints for both of your tables and I am fairly sure that you will see a constraint on the AssignedTo Column.
-
Columns with constraints or keys can not have null values. You will need to either eliminate the constraint on the AssignedTo column or will have to provide the same value from the insert in both places. In the db if you run sp_help [TableName] you will see the constraints for both of your tables and I am fairly sure that you will see a constraint on the AssignedTo Column.
I found out what the problem was. I was leaving the AssignedTo field unassigned, but the parameter was automatically being populated with a value of 0. And ofcourse there is no User in the User table with an ID of 0, therefore it was throwing that error. So all I had to do was put an IF statement in place. If the Value was 0, make the parameter = (variable = System.DBNull.Value) Problem sorted. Thank you both for your replies! :)