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: