We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,379 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

ASP.Net Login Page using C#

Hi Anyone,

I've made a web application, and now I want my web login by username and password as below but it's have got error('Login.WebForm1.DBConnection(string, string)': not all code paths return a value) anyone who can help me?

private bool DBConnection(string strUserName, string strPassword)
		{
			string LoginSQL;
			OleDbConnection MyConn = new OleDbConnection(ConfigurationSettings.AppSettings["strConn"]);
			OleDbCommand MyCmd = new OleDbCommand("sp_ValidateUser", MyConn);

			MyCmd.CommandType = CommandType.StoredProcedure;

			OleDbParameter objParam1, objParam2;

			objParam1 = MyCmd.Parameters.Add("@UserName", OleDbType.Char);
			objParam2 = MyCmd.Parameters.Add("@Password", OleDbType.Char);
			//returnParam = MyCmd.Parameters.Add ("@Num_of_User", OleDbType.Integer);
            
			objParam1.Direction = ParameterDirection.Input;
			objParam2.Direction = ParameterDirection.Input;
			//returnParam.Direction = ParameterDirection.ReturnValue;

			objParam1.Value = txtUserName.Text;
			objParam2.Value = txtPassword.Text;

			try
			{
				if(MyConn.State == ConnectionState.Closed)
				{
					MyConn.Open();
					
				}

				OleDbDataReader objReader;
				objReader = MyCmd.ExecuteReader(CommandBehavior.CloseConnection);

				while(objReader.Read())
				{
				
					if ((string)objReader.GetValue(0) != "1")
					{
						lblMessage.Text = "Invalid Login!";
						//return false;
					}
					else
					{
						objReader.Close();
						return true;
					}
					
				}		
			
			}
			catch(Exception ex)
			{
				lblMessage2.Text = "Error Connecting to the database!";
				
			}
				
		
		}

Could you please advise if you have any idea?
Thank you very much,

BeeNarak :cry:

2
Contributors
1
Reply
2 Hours
Discussion Span
7 Years Ago
Last Updated
2
Views
Question
Answered
BeeNarak
Newbie Poster
8 posts since Jul 2005
Reputation Points: 14
Solved Threads: 0
Skill Endorsements: 0
Question Self-Answered as of 7 Years Ago

Yup! **Thank you for providing the error message ***

The error message tells you the exact problem you have...and what you did to cause it...sort of.

Error: ('Login.WebForm1.DBConnection(string, string)': not all code paths return a value)

TRANSLATED: Not all conditions return a true or false value for the function DBConnection. And by defnition a Function returns a value. In this case it is a boolean value.... i.e. True, False.

So what you did was eliminate (comment out) the piece code that is required.

//return false;

take the comments out and you should be good to go! Why? Beacuse if the program goes into the If statment (which in turn is true) no value is ever returned for the Function.

Paladine
Master Poster
Team Colleague
824 posts since Feb 2003
Reputation Points: 211
Solved Threads: 27
Skill Endorsements: 0

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0557 seconds using 2.63MB