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;

				if(MyConn.State == ConnectionState.Closed)

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

					if ((string)objReader.GetValue(0) != "1")
						lblMessage.Text = "Invalid Login!";
						//return false;
						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:

Votes + Comments
Thanks for providing the ERROR message!!!!
11 Years
Discussion Span
Last Post by Paladine

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.