3 Replies - 833 Views - Last Post: 29 May 2010 - 06:35 AM Rate Topic: -----

#1 pdkharkar  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 63
  • View blog
  • Posts: 345
  • Joined: 19-January 09

query is right but not working

Posted 26 May 2010 - 09:22 PM

I am trying to authenticate manually using the two text boxes
and when i accept the names from user , they are checked in the database
and if the correct username and password combination is found then the redirection occurs
but this is not working
i tried to print the result of the query on textBoxes and everytime it return -1 as the password
here is the code
protected void Button1_Click(object sender, EventArgs e)
    {
        string user = txtUsername.Text.ToString();
        string passwd = stn.executeNonQuery("select Passwd from MemberMaster where UserName = '" + user + "'" ).ToString();
        TextBox1.Text = user;
        TextBox2.Text = passwd;
        if (txtUsername.Text == user && txtPassword.Text == passwd)
        {
            Response.Redirect("EndUser.aspx");

        }
       /// else
        //{
         //   Response.Redirect("Gallery.htm");
       // }
    }


Is This A Good Question/Topic? 0
  • +

Replies To: query is right but not working

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: query is right but not working

Posted 26 May 2010 - 09:35 PM

Well that code is never going to work for what you're trying to do. ExecuteNonQuery simply returns the number of rows affected by your query, and with a select statement it's going to always return -1 as no rows are affected
Was This Post Helpful? 1
  • +
  • -

#3 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: query is right but not working

Posted 27 May 2010 - 06:56 AM

If you are only returning a single value from single column then you can use the ExecuteScalar to get the password from the database.
Was This Post Helpful? 1
  • +
  • -

#4 JITHU  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 62
  • View blog
  • Posts: 201
  • Joined: 02-July 07

Re: query is right but not working

Posted 29 May 2010 - 06:35 AM

As Jayman said, use ExecuteScalar method instead of ExecuteNonQuery.
Just an advice: Your code is prone to sql injections, so if it's a real world project, it's better that you use parametrized queries or stored procedures.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1