Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

public bool in model

Posted on 2012-12-21
2
Medium Priority
?
337 Views
Last Modified: 2012-12-21
public bool Passwordchange(string _Username, string _Password)
{
	using (cn == new SqlConnection("")) {
		string _sql = "sp";
		if (_Password != "") {
			DecryptText obj = new DecryptText();
			_Password = obj.QueryStringEncode(_Password.Trim);
		}
		object cmd = new SqlCommand(_sql, cn);
		cmd.CommandType = CommandType.StoredProcedure;
		cmd.Parameters.Add(new SqlParameter("@username", SqlDbType.VarChar)).Value = _Username;
		cmd.Parameters.Add(new SqlParameter("@NewPassword", SqlDbType.VarChar, 15)).Value = _Password;
		try {
			cn.Open();
			cmd.ExecuteNonQuery();
			return true;
		} catch (Exception ex) {
			return false;
		} finally {
			cn.Close();
			cmd.Dispose();
		}

	}
}

Open in new window


Public bool keep getting error to use enum, class ect.
0
Comment
Question by:Seven price
2 Comments
 
LVL 41

Accepted Solution

by:
Kyle Abrahams earned 2000 total points
ID: 38714380
Try adding static.   A module can't have any instance functions . . . only static/shared (c# / vb.net) functions.

public static bool Passwordchange(string _Username, string _Password)

and FYI I would use a variable otherwise your connection isn't closed/disposed.

eg:

bool result;

result = true;

catch
{
 result = false;
  // other code
}

finally
{

   conn.Close();
   conn.dispose();
   return result;
}
0
 
LVL 9

Author Closing Comment

by:Seven price
ID: 38714388
tks
0

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question