RSS Forums RSS
Please support our C# advertiser: Programming Forums
Views: 16316 | Replies: 1 | Solved
Reply
Join Date: Jul 2005
Posts: 8
Reputation: BeeNarak is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
BeeNarak BeeNarak is offline Offline
Newbie Poster

ASP.Net Login Page using C#

  #1  
Jul 12th, 2005
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:
Last edited by Paladine : Jul 12th, 2005 at 3:11 pm. Reason: Adding the CODE Blocks!!!!!!!!!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2003
Location: Canada
Posts: 786
Reputation: Paladine has a spectacular aura about Paladine has a spectacular aura about Paladine has a spectacular aura about 
Rep Power: 9
Solved Threads: 25
Colleague
Paladine's Avatar
Paladine Paladine is offline Offline
Master Poster

Re: ASP.Net Login Page using C#

  #2  
Jul 12th, 2005
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.
Assistant Manager, Regional Pharmacy Information Systems
TLC Services Website (Under Construction)
Updated : ASP.Net Login Code
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 12:07 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC