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:

Paladine commented: Thanks for providing the ERROR message!!!! +4

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.