INSERT语句与FOREIGN KEY约束“FK_assigntask_admin”冲突。冲突发生在数据库“fypmanagemnt”,表“dbo.admin”,列“admin_ID”中。 [英] The INSERT statement conflicted with the FOREIGN KEY constraint "FK_assigntask_admin". The conflict occurred in database "fypmanagemnt", table "dbo.admin", column 'admin_ID'.

查看:112
本文介绍了INSERT语句与FOREIGN KEY约束“FK_assigntask_admin”冲突。冲突发生在数据库“fypmanagemnt”,表“dbo.admin”,列“admin_ID”中。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到了上述错误。你可以帮我PLZ。

我在分配的任务表中插入数据。以下是分配的任务表的列。 assignt_ID,assignt_title,assignt_description,assignt_to,assignt_time,assignt_deadline,assign_projectname,assign_milestone,assign_priority,FK_sup_ID,FK_stu_ID,FK_admin_ID,FK_grp_ID



FK_admin_ID与admin表有关系。但是当我在分配的任务表中插入数据时,我得到了管理员ID的外键错误。

请帮帮我





I am getting the above mentioned error. Can u help me plz.
I am inserting the data in assigned task table.Following are the columns of assigned task table. assignt_ID,assignt_title,assignt_description,assignt_to,assignt_time,assignt_deadline, assign_projectname,assign_milestone,assign_priority,FK_sup_ID,FK_stu_ID,FK_admin_ID,FK_grp_ID

FK_admin_ID has relationship with the admin table. But when i insert the data in assigned task table i m getting the error of foreign key of admin ID.
Please help me out


public int sup_groupuploadtask(string projectname, string tasktitle, string taskdescription, string milestone, string groupname, string taskstartdatetime, string taskduedatetime, string priority, string supID, string grpID)
        {

            int idchecking = (from s in dc.AssignTasks
                              select s).Count();
            if (idchecking > 0)
            {
                return 1;
            }
            else
            {
                try
                {
                    int idd;
                    int iddchecking = (from s in dc.AssignTasks

                                       select s).Count();

                    if (iddchecking > 0)
                        idd = (from s in dc.AssignTasks
                               select s.assignt_ID).Max();

                    else
                        idd = 0;
                    bool check = false;
                    AssignTask at = new AssignTask();
                    at.assign_projectname = projectname;
                    at.assignt_title = tasktitle;
                    at.assignt_description = taskdescription;
                    at.assign_milestone = milestone;
                    at.assignt_to = groupname;

                    DateTime taskassigndate = Convert.ToDateTime(taskstartdatetime);
                    at.assignt_time = taskassigndate;

                    DateTime taskduedate = Convert.ToDateTime(taskduedatetime);
                    at.assignt_deadline = taskduedate;
                    at.assign_priority = priority;
                    dc.AssignTasks.InsertOnSubmit(at);
                    dc.SubmitChanges();
                    check = true;
                    if (check == true)
                    {
                        return 3;
                    }
                    else
                        return 4;

                }
                catch
                {
                    return 2;
                }

            }









请帮助我,我将非常感谢您的时间。



我尝试过的事情:



我已经创建了置于已分配任务ID的admin的外键与admin ID的主键之间的关系。但仍然出现错误。





Please help me , i will be highly thankful for your time.

What I have tried:

I have created the relation between foreign key of admin placed in assigned task id and primary key of admin ID . but still getting error.

推荐答案

您显示的代码没有明显的INSERT:有几个Linq Selects,但没有可见的数据库更改代码 - 所以我们无法具体说明你需要做些什么来解决它!

可能你需要找到实际执行INSERT操作的代码,并在那里修复它。很可能,这是你需要查看的 AssignTasks.InsertOnSubmit 方法。

但是从错误中可以看出你所做的很明显,甚至如果我们看不到代码。

您试图将一行插入到与另一个表具有FOREIGN KEY关系的表中,并且您尝试为该列设置的值另一个表中不存在 - 所以如果SQL允许你插入行,那么数据库中的数据会不一致,它不允许这样做。正常原因是以错误的顺序向表中插入行 - 您必须先插入主表,然后再插入到以后具有FOREIGN KEY关系的表中,以便数据始终保持一致。
The code you show doesn't do an obvious INSERT: there are a couple of Linq Selects, but no database change code is visible - so we can't be specific about exactly what you need to do to fix it!
Probably, you need to find the code where you actually do the INSERT operation, and fix it there. In all probability, it's your AssignTasks.InsertOnSubmit method you need to look at.
But it's pretty obvious from the error what you have done, even if we can't see the code.
You are trying to insert a row into a table which has a FOREIGN KEY relationship with a different table, and the value you are trying to set for that column does not exist in the other table - so if SQL allowed you to INSERT the row, then the data in the DB would be inconsistent, it it won't allow that. The normal cause of this is inserting rows to tables in the wrong order - you have to insert into the primary table first, then to the table which has the FOREIGN KEY relationship later, so that the data is always consistent.


这篇关于INSERT语句与FOREIGN KEY约束“FK_assigntask_admin”冲突。冲突发生在数据库“fypmanagemnt”,表“dbo.admin”,列“admin_ID”中。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆