Click here to Skip to main content
15,891,423 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hey all

i have 1 login form for 2 users one is admin and second is simple user

when i login from theri password then its fine and working but when ienter worng password it gives me error CANNOT FIND TABLE 0

CODE

C#
public int Loginuser1(string UserName, string Password)
       {
           // return the values if Admin then 1 else 2 for User
          int a = Convert.ToInt32( db.ExecuteDataSet("splogin3", new object[] { UserName, Password }).Tables[0].Rows[0][0].ToString());

          return a;



       }




AND login button code is

C#
protected void Button1_Click(object sender, EventArgs e)
        {
            if (cd.Loginuser1(UserName.Text, Password.Text)==1)
            {
                Session["UserID2"] = cd.Loginuser1(UserName.Text, Password.Text);
                Session["Login4"] = UserName.Text;
                Session["Login5"] = Password.Text;
                Lgin.Text = ("Login Successfully");
                Response.Redirect("DocUpload.aspx");



                Lgin.Text = ("Incorrect Passsword");
            }

            else if (cd.Loginuser1(UserName.Text, Password.Text)==2)
            {
                Session["UserID"] = cd.Loginuser1(UserName.Text, Password.Text);
                Session["Login2"] = UserName.Text;
                Session["Login3"] = Password.Text;
                Lgin.Text = ("Login Successfully");
                Response.Redirect("InfoDoc.aspx");

                Lgin.Text = ("Incorrect Passsword");
            }
        }



HOW TO SOLVE THIS ANY HELP PLEASE
Posted

1 solution

C#
DataSet ds = db.ExecuteDataSet("splogin3", new object[] { UserName, Password })
if (ds.Tables.Count>0)
{
  // then do your checking
}
 
Share this answer
 
Comments
Diya Ayesa 26-Jul-13 13:33pm    
this code is in button coding or in above funtion ..???the error in above funtion

public int Loginuser1(string UserName, string Password)
{
// return the values if Admin then 1 else 2 for User
int a = Convert.ToInt32( db.ExecuteDataSet("splogin3", new object[] { UserName, Password }).Tables[0].Rows[0][0].ToString());

return a;



}

IN THIS FUNTION ERROR OCCUR
ZurdoDev 26-Jul-13 13:37pm    
Perhaps you should break up that line of code. The error is very clear. You are trying to access Tables[0] and it does not exist. You are trying to do too much in a single line of code. That is why you need to break it up, check if Tables[0] even exists and then continue on.
Diya Ayesa 26-Jul-13 13:58pm    
if i do this code

Collapse | Copy Code

public bool Loginuser1(string UserName, string Password)
{
DataSet ds = db.ExecuteDataSet("splogin3", new object[] { UserName, Password });
if(ds.Tables.Count>0)
{
return true;
}
return false;
}


then error in button code that i s

Operator '==' cannot be applied to operands of type 'bool' and 'int'

in this funtion
Collapse | Copy Code

protected void Button1_Click(object sender, EventArgs e)
{
if (cd.Loginuser1(UserName.Text, Password.Text)==1)
{
Session["UserID2"] = cd.Loginuser1(UserName.Text, Password.Text);
Session["Login4"] = UserName.Text;
Session["Login5"] = Password.Text;
Lgin.Text = ("Login Successfully");
Response.Redirect("DocUpload.aspx");



Lgin.Text = ("Incorrect Passsword");
}

else if (cd.Loginuser1(UserName.Text, Password.Text)==2)
{
Session["UserID"] = cd.Loginuser1(UserName.Text, Password.Text);
Session["Login2"] = UserName.Text;
Session["Login3"] = Password.Text;
Lgin.Text = ("Login Successfully");
Response.Redirect("InfoDoc.aspx");

Lgin.Text = ("Incorrect Passsword");
}
}



then hwo to solve this
Diya Ayesa 26-Jul-13 13:58pm    
NOW FINE....
ZurdoDev 26-Jul-13 14:00pm    
Good to hear.

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