如何在linq中使用outputparameter调用存储过程 [英] How to call stored procedure with outputparameter in linq

查看:141
本文介绍了如何在linq中使用outputparameter调用存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作密码更改表单。以下是aspx: -



I'm making a password change form . Below is the aspx:-

<div class="container" id="passdiv">

        <div id="somemoredetail" class="row">

            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="BtnSave" EventName="Click" />
                </Triggers>
                <ContentTemplate>


                    <h3 class="text-center">Change Password :-</h3>
                    <div class="clearfix separator"></div>

                    <asp:LinkButton ID="BtnSave" runat="server" class="btn btn-info" type="button" Text="Save"

                        Style="border-radius: 50%; height: 50px" OnClick="BtnSave_Click">
                    <span class="glyphicon glyphicon-floppy-save" style="margin-removed10px"></span>
                    </asp:LinkButton>


                    <div class="col-md-6 col-xs-12">

                        <div class="form-group text-center">
                            <div class="form-inline">
                                <p>
                                    User Name :-
                                 <asp:Label ID="user" runat="server" Text="User"></asp:Label>
                                </p>
                            </div>

                            <div class="form-inline">
                                <p>
                                    Old Password :-
                                    <asp:TextBox ID="old" TextMode="Password" runat="server" Style="border: 1px solid grey"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="RqdFldVldoldpass" runat="server" ErrorMessage="Enter -- 'Old Password'" Text="#" ControlToValidate="old" ForeColor="Red"></asp:RequiredFieldValidator>
                                </p>
                            </div>
                            <div class="form-inline">
                                <p>
                                    New Password :-
                <asp:TextBox ID="newpass" TextMode="Password" Style="border: 1px solid grey" runat="server"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="RqdFldVldnewpass" runat="server" ErrorMessage="Enter -- 'New Password'" Text="#" ControlToValidate="newpass" ForeColor="Red"></asp:RequiredFieldValidator>
                                </p>
                            </div>
                            <div class="form-inline">
                                <p>
                                    Confirm New Password :-
                <asp:TextBox ID="confirmnew" TextMode="Password" Style="border: 1px solid grey" runat="server"></asp:TextBox>
                                    <asp:CompareValidator ID="ComparePassword" runat="server" ErrorMessage="New PassWord and Confirm New Password Don't Match" ControlToCompare="confirmnew" ControlToValidate="newpass" ForeColor="Red">#</asp:CompareValidator>
                                </p>
                            </div>
                        </div>

                    </div>


                </ContentTemplate>
            </asp:UpdatePanel>

        </div>


        <asp:ValidationSummary ID="ValidationSummaryPass" runat="server" ShowMessageBox="True" ShowSummary="False" />

    </div>





我创建了一个存储过程来更改密码: -



创建proc passwrdchange

@ ID bigint,

@oldpass varchar(MAX),

@newpass varchar(MAX),

@Out char输出

As

开始

设置@ Out ='F'



if(从User_Information中选择密码其中ID = @ ID)= @ oldpass

开始

更新User_Information设置密码= @ newpass,

@ Out ='T'

结束



结束



现在,当我通过LINQ调用它时,它是给出错误无效参数: -





I've created a stored procedure to make changes for password:-

create proc passwrdchange
@ID bigint,
@oldpass varchar(MAX),
@newpass varchar(MAX),
@Out char output
As
Begin
Set @Out='F'

if(Select Password from User_Information where ID=@ID)=@oldpass
Begin
Update User_Information Set Password=@newpass,
@Out='T'
End

End

Now when I'm calling it via LINQ it's giving error "invalid arguments":-

protected void BtnSave_Click(object sender, EventArgs e)
   {
        using(SampleDataContext dbContext=new SampleDataContext())
        {
            char outpt;
            int id = Convert.ToInt32(Session["USERID"]);
            dbContext.passwrdchange(id, old.Text, newpass.Text, ref outpt);
        }
   }





请帮帮我。



Please Help me With This.

推荐答案

最后我得到了解决方案: -



Finally I got the solution :-

protected void BtnSave_Click(object sender, EventArgs e)
  {
      using (SampleDataContext dbContext = new SampleDataContext())
      {
          System.Nullable<char> outpt = null;
          long id = Convert.ToInt64(Session["USERID"]);
          dbContext.passwrdchange(id, old.Text.ToString().Trim(), newpass.Text.ToString().Trim(), ref outpt);

          if(outpt.ToString()=="T")
          {
              ClientScript.RegisterStartupScript(this.GetType(), "SuccessMsg", "<script>alert('Password Changed Successfully')</script>");
          }

          else
          {
              ClientScript.RegisterStartupScript(this.GetType(), "ErrorMsg", "<script>alert('Password Not Changed')</script>");
          }
      }
  }


这篇关于如何在linq中使用outputparameter调用存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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