Click here to Skip to main content
15,919,479 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i'm designing a login page using 3tier architecture

In business access layer :

public SqlDataReader login()
{
ob.getcon();

SqlDataReader dr = ob.exdr("select client_pwd from Register where email='" + email + "'");
return dr;



}

In login page :

C#
protected void Button1_Click(object sender, EventArgs e)
       {
           string email = TextBox3.Text;
           ba.login();

           if (!dr.Read())
       {
          Label4.Text="Invalid User";
       }
       else
       {
           if (dr[0].ToString() == TextBox2.Text)
           {
               Response.Redirect("~/mainPage.aspx");
           }
           else
           {
              Label4.Text="Wrong Password";

           }


       }


here it is showing that dr doesnot exist in current context.how to solve this
Posted
Comments
R-a-v-i-k-u-m-a-r 2-Apr-14 6:18am    
Did you add the business layer project reference to presentatio layer?
Did you import the namespace of bll into your login page?
sruthyjoseph 2-Apr-14 6:26am    
no..how to do it? thank you

if (dr[0].ToString() == TextBox2.Text)
You have not defined dr in this class.

In general the UI should not know about the data reader.
Let the BC handle this and return the result to the UI as a data model.
 
Share this answer
 
Comments
sruthyjoseph 2-Apr-14 6:22am    
so u mean i need to write dat code in Business layer itself.but wen i write it there it is showing that TextBox and Labels doesnot exist in current context..
Thank you
error is because you are reading a variable which is declared in class.
improve your solution, pass email to Login() function. Instead of returning a DataReader. return a table or row. eg.
C#
public static DataTable GetTable(SqlCommand cmd)
        {
            DataTable tbl = null;
            SqlConnection conn = null;
            try
            {
                conn = //your connection;
                cmd.Connection = conn;
                tbl = new DataTable();
                SqlDataReader dr = cmd.ExecuteReader();
                tbl.Load(dr);

                dr.Close();
                dr.Dispose();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }
            return tbl;
        }

protected void Button1_Click(object sender, EventArgs e)
       {
           string email = TextBox3.Text;
SqlCommand cmd = new SqlCommand();
cmd="select client_pwd from Register where email='" + email + "'"
          DataTable tbl = ba.GetTable(cmd)

           if (tbl == null && tbl.Rows.Count == 0)
       {
          Label4.Text="Invalid User";
       }
       else
       {
          //your code


       }
 
Share this answer
 
v3
Chexk this link
http://msdn.microsoft.com/en-us/library/f3st0d45(v=vs.100).aspx[^]
after that import your bll name into yourpage

And write the code as

C#
protected void Button1_Click(object sender, EventArgs e)
       {
           string email = TextBox3.Text;
           SqlDataReader dr=ba.login();

           if (!dr.Read())
       {
          Label4.Text="Invalid User";
       }
       else
       {
           if (dr[0].ToString() == TextBox2.Text)
           {
               Response.Redirect("~/mainPage.aspx");
           }
           else
           {
              Label4.Text="Wrong Password";

           }


       }</pre>

=
 
Share this answer
 
v2
You are missing only SqlDataReader value
.....
  SqlDataReader dr=ba.login(); 
 
Share this answer
 
Comments
sruthyjoseph 2-Apr-14 9:14am    
u r right..i missed that..thanku so much :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900