批准文档时出错 [英] error when approve document

查看:80
本文介绍了批准文档时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试按照代码批准文件

  if (e.CommandName ==   _ Approve
{
/ / 使用(SqlConnection con = DataAccess.GetConnected())
使用( SqlConnection con = new
SqlConnection(ConfigurationManager.ConnectionStrings [ mydms]
.ConnectionString))
{
try
{
con.Open();
int rowindex = Convert.ToInt32(e.CommandArgument);
GridViewRow row =(GridViewRow)
((Control)e.CommandSource).NamingContainer;
Button Prove_Button =(Button)row.FindControl( BtnApprove);
SqlCommand cmd = new SqlCommand( approve ,con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add( new SqlParameter( @UserID,UserID));
cmd.Parameters.Add( new SqlParameter( @DocID,DocID));
cmd.Parameters.Add( new SqlParameter( @ApproveID,ApproveID));
int result = cmd.ExecuteNonQuery();
if (result!= 0
{
GrdFileApprove。的DataBind();
}
}

catch
{
apfi.Text = Not Approve;



}
最后
{
con.Close() ;
}
}
}


其他 if (e.CommandName == _ Reject
{
使用(SqlConnection con = new
SqlConnection(ConfigurationManager.ConnectionStrings
[ mydms]。ConnectionString))
{
尝试
{
con.Open();
int rowindex = Convert.ToInt32(e.CommandArgument);
GridViewRow row =(GridViewRow)
((Control)e.CommandSource).NamingContainer;
LinkBut​​ton Prove_Button =(LinkBut​​ton)row.FindControl( Button1);
SqlCommand cmd = new SqlCommand( sprejectapprove ,con);

cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add( new SqlParameter( @UserID,用户ID));
cmd.Parameters.Add( new SqlParameter( @DocID,DocID));
cmd.Parameters.Add( new SqlParameter( @ApproveID,ApproveID));
int result = cmd.ExecuteNonQuery();
if (result!= 0
{
GrdFileApprove。的DataBind();
}
}

catch
{
apfi.Text = Rejct;
}
最后
{
con.Close();
}
}
}







和商店程序批准是

 @UserID int,
@DocID int,
@ApproveID int
as
insert in Approval(UserID, DocID,ApproveID)
VALUES(@ UserID,@ DocID,@ ApproveID)







当我调试代码并单击一个接受按钮时,它会向我显示批准部分中的catch错误



INSERT语句与FOREIGN KEY约束冲突FK_Approval_ApproveType。数据库DMSFYPP,表dbo.ApproveType,ApproveID列发生冲突。声明已终止





任何帮助





thanku

解决方案

Quote:

INSERT语句与FOREIGN KEY约束冲突FK_Approval_ApproveType。数据库DMSFY发生冲突PP,表dbo.ApproveType,列'ApproveID'。该声明已被终止



让我解释一下这个问题。



有两张表。



  • 批准
  • ApproveType




他们之间存在一种名为 FK_Approval_ApproveType 的关系。



编写以下代码时...

 插入 进入批准(UserID,DocID,ApproveID)
VALUES @ UserID @ DocID @ ApproveID ApproveType

这意味着表格中应存在 @ApproveID 的记录。



例如,如果要为 ApproveI插入行D - 3,然后在 ApprovalType 表中应该存在该ID的记录。



您可以通过在函数内部放置断点并检查 ApproveID 来了解您要发送的批准类型。


i try to approve documents thrugh following code

if (e.CommandName == "_Approve")
        {
            //using (SqlConnection con = DataAccess.GetConnected())
            using (SqlConnection con = new 
          SqlConnection(ConfigurationManager.ConnectionStrings["mydms"]
           .ConnectionString))
            {
                try
                {
                    con.Open();
                    int rowindex = Convert.ToInt32(e.CommandArgument);
                    GridViewRow row = (GridViewRow)
                   ((Control)e.CommandSource).NamingContainer;
                    Button Prove_Button = (Button)row.FindControl("BtnApprove");
                    SqlCommand cmd = new SqlCommand("approve", con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter("@UserID", UserID));
                    cmd.Parameters.Add(new SqlParameter("@DocID", DocID));
                    cmd.Parameters.Add(new SqlParameter("@ApproveID", ApproveID));
                    int result = cmd.ExecuteNonQuery();
                    if (result != 0)
                    {
                        GrdFileApprove.DataBind();
                    }
                }

                catch
                {
                    apfi.Text = "Not Approve";



                }
                finally
                {
                    con.Close();
                }
            }
        }


        else if (e.CommandName == "_Reject")
        {
            using (SqlConnection con = new 
          SqlConnection(ConfigurationManager.ConnectionStrings
        ["mydms"].ConnectionString))
            {
                try
                {
                    con.Open();
                    int rowindex = Convert.ToInt32(e.CommandArgument);
                    GridViewRow row = (GridViewRow)
                    ((Control)e.CommandSource).NamingContainer;
                    LinkButton Prove_Button = (LinkButton)row.FindControl("Button1");
                    SqlCommand cmd = new SqlCommand("sprejectapprove", con);

                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter("@UserID",UserID));
                    cmd.Parameters.Add(new SqlParameter("@DocID", DocID));
                    cmd.Parameters.Add(new SqlParameter("@ApproveID", ApproveID));
                    int result = cmd.ExecuteNonQuery();
                    if (result != 0)
                    {
                        GrdFileApprove.DataBind();
                    }
                }

                catch 
                {
                    apfi.Text = "Rejct";
                }
                finally
                {
                    con.Close();
                }
            }
        }




and store procedure of approve is

@UserID int,
  @DocID int,
 @ApproveID int
as
insert into Approval(UserID,DocID,ApproveID)
VALUES(@UserID,@DocID,@ApproveID)




when i debug the code and click an accept button it show me error in catch in approve part

"The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Approval_ApproveType". The conflict occurred in database "DMSFYPP", table "dbo.ApproveType", column 'ApproveID'. The statement has been terminated"


any help


thanku

解决方案

Quote:

"The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Approval_ApproveType". The conflict occurred in database "DMSFYPP", table "dbo.ApproveType", column 'ApproveID'. The statement has been terminated"


Let me explain the issue.

There are two tables.


  • Approval
  • ApproveType


There is a Relationship between them named as "FK_Approval_ApproveType".

When you write the following code...

Insert into Approval(UserID, DocID, ApproveID)
VALUES(@UserID, @DocID, @ApproveID)


the value of @ApproveID should be present in Table ApproveType.
That means a record for the @ApproveID should exist in the table.

For example if you are inserting row for ApproveID - 3, then there should be a Record existing for that ID in ApprovalType Table.

You can know what is the Approval Type you are sending by putting a Break Point inside the function and checking the ApproveID.


这篇关于批准文档时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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