Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如果找到记录,则从表A填充编辑记录屏幕,否则从表b填充编辑记录屏幕_C#_Sql_Asp.net - Fatal编程技术网

C# 如果找到记录,则从表A填充编辑记录屏幕,否则从表b填充编辑记录屏幕

C# 如果找到记录,则从表A填充编辑记录屏幕,否则从表b填充编辑记录屏幕,c#,sql,asp.net,C#,Sql,Asp.net,希望在asp.net C#应用程序中添加“编辑”功能,以便特定角色的用户可以创建“标准”用户提交的记录的编辑版本。原始记录保留在表A中,编辑后的版本存储在表B中(参考原始记录)。但是,我想补充的是,如果编辑点击他们已经编辑过的记录的编辑按钮,可以询问他们(通过弹出窗口?)是否要创建新的编辑记录,或者创建新的编辑记录并根据此答案加载页面 当前,用户单击gridview上的编辑问题链接按钮: <asp:TemplateField> <ItemTemplate>

希望在asp.net C#应用程序中添加“编辑”功能,以便特定角色的用户可以创建“标准”用户提交的记录的编辑版本。原始记录保留在表A中,编辑后的版本存储在表B中(参考原始记录)。但是,我想补充的是,如果编辑点击他们已经编辑过的记录的编辑按钮,可以询问他们(通过弹出窗口?)是否要创建新的编辑记录,或者创建新的编辑记录并根据此答案加载页面

当前,用户单击gridview上的编辑问题链接按钮:

<asp:TemplateField>
     <ItemTemplate>
        <asp:LinkButton ID="Edit" CommandArgument='<%# Eval("QuestionID") %>' runat="server" CommandName="editQuestion">Edit Question</asp:LinkButton>
    </ItemTemplate>
</asp:TemplateField>
它使用存储过程加载页面,该存储过程从表a中提取适用的记录:

using (Conn)
            {
                SqlCommand command = new SqlCommand("sp_CloneSElect", Conn);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.Add(new SqlParameter("@QuestionID", SqlDbType.BigInt));
                command.Parameters["@QuestionID"].Value = Convert.ToInt32(Request["Id"]);
                Conn.Open();
                SqlDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    txt_ImageID.Text = reader["ImageID"].ToString();
                    txt_Date.Text = reader["SubmitDate"].ToString();
                    txt_Stem.Text = reader["Stem"].ToString();
                    txt_RespA.Text = reader["RespA"].ToString();
                    txt_RespB.Text = reader["RespB"].ToString();
                    txt_RespC.Text = reader["RespC"].ToString();
                    txt_RespD.Text = reader["RespD"].ToString();
                    txt_RespE.Text = reader["RespE"].ToString();
                    DDResponse.SelectedValue = reader["Answer"].ToString();
                    txt_Critique.Text = reader["Critique"].ToString();
                    txt_KeyObjective.Text = reader["KeyObjective"].ToString();
                    txt_References.Text = reader["References"].ToString();
                    DDPractice1.SelectedValue = reader["PracticeArea1"].ToString();
                    DDPractice2.SelectedValue = reader["PracticeArea2"].ToString();
                    DDPractice3.SelectedValue = reader["PracticeArea3"].ToString();
                    DDPractice4.SelectedValue = reader["PracticeArea4"].ToString();
                    txt_QuestionID.Text = reader["Id"].ToString();
                    txt_IsCloneOf.Text = reader["IsCloneOf"].ToString();
                }
                reader.Close();
                DataTable dt = new DataTable();
                using (Conn)
                {
                    SqlDataAdapter ad = new SqlDataAdapter("SELECT QuestionID, Images2.ImageID, ImageFile, ImageContent, ImageName, SEQ_NUM from qimages join Images2 on qimages.imageid = images2.imageid where QuestionID = @QuestionID", Conn);
                    ad.SelectCommand.Parameters.Add("QuestionID", SqlDbType.BigInt).Value = txt_QuestionID.Text;
                    ad.Fill(dt);
                }
                dlImages.DataSource = dt;
                dlImages.DataBind();
            }

我可以找出如何让底层存储过程执行逻辑,从表b(如果存在)中提取,否则从表a、、中提取,但不知道如何向用户提问并将新变量添加到存储过程的输入中,或者根据用户对问题的回答更改调用的存储过程是否更容易“您已经编辑了此问题,是否要查看此记录或创建新的编辑版本?”

OT,但很重要:当您说
using(Conn)时
,您是否理解
Conn
将在
using
块的末尾被释放,但不会设置为
null
?这就是为什么
using
的约定是在
using
块中声明引用(例如
using(var foo=new foo()){
),以及为什么您从未看到
使用(foo)
嵌套在
使用(foo)中
。您不需要或不想两次处理
Conn
,当然也不希望它位于使用处理它的
块的
范围之外。为了简单起见,不要在SP中执行此操作。而是进行另一次查询,检查
表A
是否存在任何值。如果不存在,请转到
表B
en您可以在SP.@AT-2016中使用
IF
语句-我不知道如何创建弹出消息,询问您是否要创建新的或“重新编辑”现有的编辑,然后根据该响应传递一个值。Asp.net和C的新增功能,请参阅此弹出窗口-OT,但很重要:当您说
使用(Conn)时
,您是否理解
Conn
将在
using
块的末尾被释放,但不会设置为
null
?这就是为什么
using
的约定是在
using
块中声明引用(例如
using(var foo=new foo()){
),以及为什么您从未看到
使用(foo)
嵌套在
使用(foo)中
。您不需要或不想两次处理
Conn
,当然也不希望它位于使用处理它的
块的
范围之外。为了简单起见,不要在SP中执行此操作。而是进行另一次查询,检查
表A
是否存在任何值。如果不存在,请转到
表B
en您可以在SP.@AT-2016中使用
IF
语句-我不知道如何创建弹出消息,询问您是否要创建新的或“重新编辑”现有的编辑,然后根据该响应传递一个值。Asp.net和C的新增功能#请参阅此弹出窗口-
using (Conn)
            {
                SqlCommand command = new SqlCommand("sp_CloneSElect", Conn);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.Add(new SqlParameter("@QuestionID", SqlDbType.BigInt));
                command.Parameters["@QuestionID"].Value = Convert.ToInt32(Request["Id"]);
                Conn.Open();
                SqlDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    txt_ImageID.Text = reader["ImageID"].ToString();
                    txt_Date.Text = reader["SubmitDate"].ToString();
                    txt_Stem.Text = reader["Stem"].ToString();
                    txt_RespA.Text = reader["RespA"].ToString();
                    txt_RespB.Text = reader["RespB"].ToString();
                    txt_RespC.Text = reader["RespC"].ToString();
                    txt_RespD.Text = reader["RespD"].ToString();
                    txt_RespE.Text = reader["RespE"].ToString();
                    DDResponse.SelectedValue = reader["Answer"].ToString();
                    txt_Critique.Text = reader["Critique"].ToString();
                    txt_KeyObjective.Text = reader["KeyObjective"].ToString();
                    txt_References.Text = reader["References"].ToString();
                    DDPractice1.SelectedValue = reader["PracticeArea1"].ToString();
                    DDPractice2.SelectedValue = reader["PracticeArea2"].ToString();
                    DDPractice3.SelectedValue = reader["PracticeArea3"].ToString();
                    DDPractice4.SelectedValue = reader["PracticeArea4"].ToString();
                    txt_QuestionID.Text = reader["Id"].ToString();
                    txt_IsCloneOf.Text = reader["IsCloneOf"].ToString();
                }
                reader.Close();
                DataTable dt = new DataTable();
                using (Conn)
                {
                    SqlDataAdapter ad = new SqlDataAdapter("SELECT QuestionID, Images2.ImageID, ImageFile, ImageContent, ImageName, SEQ_NUM from qimages join Images2 on qimages.imageid = images2.imageid where QuestionID = @QuestionID", Conn);
                    ad.SelectCommand.Parameters.Add("QuestionID", SqlDbType.BigInt).Value = txt_QuestionID.Text;
                    ad.Fill(dt);
                }
                dlImages.DataSource = dt;
                dlImages.DataBind();
            }