Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm Calling a stored procedure for password change. But it is giving me Error.

What I have tried:

And On Button Click My Function is:-

C#
protected void BtnSave_Click(object sender, EventArgs e)
  {
      using (SampleDataContext dbContext = new SampleDataContext())
      {
          System.Nullable<char> outpt = null;
          System.Nullable<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('Old Password Does Not Match with Records.')</script>");
          }
      }
  }


My stored procedure is:-

SQL
ALTER proc [dbo].[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 where ID=@ID
			Set @Out='T'
		End
	
End


And My Linq .cs file function for Calling stored procedure is:-

C#
private void UpdateUser_Information(User_Information obj)
	{
		this.passwrdchange(((System.Nullable<long>)(obj.ID)), default(string), default(string),ref default(System.Nullable<char>));
	}


But this is giving me an error
A ref or out argument must be an assignable variable

Please HELP!!
Posted
Updated 6-Feb-16 17:09pm
v2
Comments
PIEBALDconsult 6-Feb-16 23:10pm    
I suspect the problem is:

ref default(System.Nullable<char>)
Deepak Kanswal Sharma 6-Feb-16 23:24pm    
So I should Replace it with char?
Sergey Alexandrovich Kryukov 6-Feb-16 23:11pm    
What part of this error message is unclear? It should be a variable, not read-only field, not constant, not immediate constant...
—SA

1 solution

Please see my comment to the question. Is anything unclear?

The problem is here:
C#
this.passwrdchange((System.Nullable<long>)(obj.ID)), default(string), default(string), ref default(System.Nullable<char>);

Here, your ref parameter is not assignable variable. This is the constant defined by the type. You need to understand passing parameters by reference. The calling method is supposed to fill in some place in memory. There is no such thing in your call. This would compile:
C#
System.Nullable<char> someVariable = // some value, null or not
this.passwrdchange((System.Nullable<long>)(obj.ID)), default(string), default(string), ref someVariable);
// but now:
// this call suggests that you can use the value
// of someVariable after the call

You have to learn this:
ref (C# Reference)[^],
out (C# Reference)[^],
Reference (computer science) - Wikipedia, the free encyclopedia[^],
Passing Parameters (C# Programming Guide)[^].

—SA
 
Share this answer
 
v2
Comments
Deepak Kanswal Sharma 6-Feb-16 23:33pm    
Oh Yeah!! I got the point. Of course it will need to assign a value to some variable. HOW SILLY OF ME!! Thanks :)
Sergey Alexandrovich Kryukov 6-Feb-16 23:34pm    
No problem.
Good luck, call again.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900