Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 2nd, 2007, 07:37 PM
Authorized User
 
Join Date: Oct 2006
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default login page

i have written SP as below.
create procedurep_login
@username varchar(25)
@password varchar(25)
as
if exists(select * from user_table where
username=@username and password=@password)
return 1
else
return 0
go

above SP is working ok but i m not able to properly coding in asp.net with c# because if i entered either correct username and password or wrong the result is same.Please send me code in asp.net
thanks
abaso jadhav


 
Old February 2nd, 2007, 07:42 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Doesn't that depend on the C# code you're using?

Can you show us what you have so far?

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old February 2nd, 2007, 08:37 PM
Authorized User
 
Join Date: Oct 2006
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi imar
i have written following code.plz tell me what is wrong.

protected void Button1_Click(object sender, EventArgs e)
    {


            string Sqlcon = ConfigurationSettings.AppSettings["sqlcon"];
            SqlConnection con = new SqlConnection(Sqlcon);
            con.Open();
            SqlCommand cmd = new SqlCommand("sp_login", con);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlParameter objParam1, objParam2;

            objParam1 = cmd.Parameters.Add(new SqlParameter("@username", SqlDbType.VarChar, (50), "username"));
            objParam2= cmd.Parameters.Add(new SqlParameter("@pasword",SqlDbType.VarChar,50,"pasw ord"));
           // cmd.Parameters.Add(new SqlParameter("@username", txtUserName.Text));
            //cmd.Parameters.Add(new SqlParameter("@pasword", txtPassword.Text));
            // cmd.Parameters[0].Value="txtUserName.Text";
            // cmd.Parameters[1].Value="txtPassword.Text";
          // int i=cmd.ExecuteNonQuery();
            objParam1.Direction = ParameterDirection.Input;
            objParam2.Direction = ParameterDirection.Input;

            objParam1.Value = txtUserName.Text;
            objParam2.Value = txtPassword.Text;


            try
            {
                if (con.State == ConnectionState.Closed)
                {
                    con.Open();

                }

                SqlDataReader objReader;
                objReader = cmd.ExecuteReader(CommandBehavior.CloseConnection) ;

                while (objReader.Read())
                {

                    if ((string)objReader.GetValue(0) != "1")
                    {
                        Label1.Text = "Invalid Login!";
                        //return false;
                    }
                    else
                    {
                        objReader.Close();
                       // return true;
                    }

                }

            }
            catch (Exception ex)
            {
                Label1.Text = "Error Connecting to the database!";

            }


    }


thanks
Abaso Jadhav

 
Old February 3rd, 2007, 05:05 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

First of all, are you aware of the new security features in ASP.NET 2 through the Membership and Role providers? In many cases, authentication like this is taken care of completely. Worth looking into.

http://quickstarts.asp.net/QuickStar...y/default.aspx

Secondly, if you post code here, can you please trim it a little so it just shows the relevant pieces? Right now, there's a lot of commented code that just makes it harder to see what's going on.

Next, take a look at this:

while (objReader.Read())
{

What are you "whiling" here? Considering a standard query that retrieves a user, you would normally expect one record, for a single user, so there's nothing to loop.

However, in your case, you're not even selecting anything. So, there's no data to read, and nothing to loop through. All you do is assign a *return value* the value of 1 or 0. This means your procedure never returns any data; all it does is return a return value.

So, you should set up a return value parameter for the Command object. Take a look here: http://msdn2.microsoft.com/en-us/library/59x02y99(VS.80).aspx for some ideas about the return value parameter.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Login Page kumar.deepak1984 JSP Basics 1 May 12th, 2008 06:41 AM
Login Page ninel General .NET 0 November 2nd, 2006 11:40 AM
Login page back to original page pablohoney Classic ASP Basics 1 October 3rd, 2006 07:09 PM
LOGIN PAGE (does not link to the next page) [email protected] Classic ASP Databases 7 April 5th, 2006 01:28 PM
Newbie Help. Login to unique login page per user Kainan Classic ASP Professional 10 May 3rd, 2005 07:47 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.