| | |
solution for not all code paths return a value for bool
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2007
Posts: 7
Reputation:
Solved Threads: 0
i have creted this code for login control:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
publicpartialclass_Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
bool Autheticated = false;
Autheticated = SiteLevelCustomAutheticationMethod(Login1.UserName, Login1.Password);
e.Authenticated = Autheticated;
if (Autheticated == true)
{
Response.Write("Home.aspx");
}
}
private bool SiteLevelCustomAutheticationMethod (string UserName, string Password)
{
bool boolReturnValue = false;
string scon = "SERVER=.; INITIAL CATALOG=Villaplus; UID=sa; PWD=ash; ";
SqlConnection con = new SqlConnection(scon);
String strSQL = "Select * From Login";
SqlCommand com = new SqlCommand(strSQL, con);
SqlDataReader Dr;
con.Open();
Dr = com.ExecuteReader();
while (Dr.Read())
{
if ((UserName == Dr["name"].ToString()) & (Password == Dr["Password"].ToString()))
{
boolReturnValue = true;
}
Dr.Close();
return boolReturnValue;
}
}
}
but it gives error:
'_Default.SiteLevelCustomAutheticationMethod(string, string)': not all code paths return a value .
please give solution for this.
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
publicpartialclass_Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
bool Autheticated = false;
Autheticated = SiteLevelCustomAutheticationMethod(Login1.UserName, Login1.Password);
e.Authenticated = Autheticated;
if (Autheticated == true)
{
Response.Write("Home.aspx");
}
}
private bool SiteLevelCustomAutheticationMethod (string UserName, string Password)
{
bool boolReturnValue = false;
string scon = "SERVER=.; INITIAL CATALOG=Villaplus; UID=sa; PWD=ash; ";
SqlConnection con = new SqlConnection(scon);
String strSQL = "Select * From Login";
SqlCommand com = new SqlCommand(strSQL, con);
SqlDataReader Dr;
con.Open();
Dr = com.ExecuteReader();
while (Dr.Read())
{
if ((UserName == Dr["name"].ToString()) & (Password == Dr["Password"].ToString()))
{
boolReturnValue = true;
}
Dr.Close();
return boolReturnValue;
}
}
}
but it gives error:
'_Default.SiteLevelCustomAutheticationMethod(string, string)': not all code paths return a value .
please give solution for this.
C# Syntax (Toggle Plain Text)
while (Dr.Read()) { if ((UserName == Dr["name"].ToString()) & (Password == Dr["Password"].ToString())) { boolReturnValue = true; } Dr.Close(); } return boolReturnValue;
Have the code that way and it should work.
•
•
Join Date: Feb 2007
Posts: 3
Reputation:
Solved Threads: 0
You should also have the DR.Close() statement outside of your loop. The general structure should be.
If you want to break out of the loop to return before reading the whole resultset, then use the break keyword. It will drop you outside of the loop.
C# Syntax (Toggle Plain Text)
Create and Open connection Create and execute a command to get a datareader Read next record Perform actions for each record. Close the reader Close the connection Return the result.
If you want to break out of the loop to return before reading the whole resultset, then use the break keyword. It will drop you outside of the loop.
Last edited by reklawnnelg; Feb 8th, 2007 at 10:00 am. Reason: Fix formatting
![]() |
Similar Threads
- Error 'not all code paths return a value' (C#)
- Resolve my problem (C#)
- ASP.Net Login Page using C# (C#)
Other Threads in the C# Forum
- Previous Thread: C# Code
- Next Thread: i need login code in C#
| Thread Tools | Search this Thread |
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# chat check checkbox client color combobox concurrency control conversion csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing encryption enum event excel file files form format forms function gdi+ globalization httpwebrequest image index input install java label list listbox listener mandelbrot math microsoftc#visualexpress mouseclick mysql networking operator path photoshop picturebox pixelinversion post prime programming radians regex remote remoting richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml






