Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Login page

Login page

Scheduled Pinned Locked Moved ASP.NET
csharpdatabasehelpasp-netsharepoint
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sarah_chandran
    wrote on last edited by
    #1

    i have a login page that accepts username and password and checks it with the value in the database,if the values match the next form is loaded otherwise error message appears. The stored procedure I used is CREATE PROCEDURE sp_User @NAME char(50),@PASSWORD varchar(50) AS SELECT COUNT(*)AS Num_of_User FROM LOGINTAB WHERE (((LOGINTAB.NAME)=@NAME) AND ((LOGINTAB.PASSWORD)=@PASSWORD)); GO The database connection does not return any error but even if i give the correct username and password i get error message""Invalid Login, please try again!";and"Invalid Login!". I got the code from the url www.daniweb.com/tutorials/tutorial24148.htm it is called "Simple ASP.Net Login Page using C#" The code is as follows private void Button1_Click(object sender, System.EventArgs e) { if (Page.IsValid) { if (DBConnection(txtUserName.Text.Trim(), txtPassword.Text.Trim())) { WebForm2 wf2=new WebForm2(); WebForm2.Visible=true; } else { lblMessage.Text = "Invalid Login, please try again!"; } } } private bool DBConnection(string txtUser, string txtPass) { SqlConnection myConn = new SqlConnection("server=;database=login;user id=;password="); SqlCommand myCmd = new SqlCommand("sp_User", myConn); myCmd.CommandType = CommandType.StoredProcedure; SqlParameter objParam1; SqlParameter objParam2; SqlParameter returnParam; objParam1 = myCmd.Parameters.Add ("@NAME", SqlDbType.Char); objParam2 = myCmd.Parameters.Add ("@PASSWORD", SqlDbType.VarChar); returnParam = myCmd.Parameters.Add ("@Num_of_User", SqlDbType.Int); objParam1.Direction = ParameterDirection.Input; objParam2.Direction = ParameterDirection.Input; returnParam.Direction = ParameterDirection.ReturnValue; objParam1.Value = txtUser; objParam2.Value = txtPass; /* Label1.Text=objParam1.Value.ToString(); Label2.Text=objParam2.Value.ToString();These 2 lines that are commented outputs the label1 and label2 with the name and password i gave in run time this is just to check if this part is working fine*/ try { if (myConn.State.Equals(ConnectionState.Closed)) { myConn.Open(); myCmd.ExecuteNonQuery(); } /*the problem is that the returnParam returns 0 and not 1 and i found this out by using a textbox that stores the returnParam TextBox1.Text=returnParam.Value.ToString(); */ if ((int)returnParam.Value<1) { lblM

    M C 2 Replies Last reply
    0
    • S sarah_chandran

      i have a login page that accepts username and password and checks it with the value in the database,if the values match the next form is loaded otherwise error message appears. The stored procedure I used is CREATE PROCEDURE sp_User @NAME char(50),@PASSWORD varchar(50) AS SELECT COUNT(*)AS Num_of_User FROM LOGINTAB WHERE (((LOGINTAB.NAME)=@NAME) AND ((LOGINTAB.PASSWORD)=@PASSWORD)); GO The database connection does not return any error but even if i give the correct username and password i get error message""Invalid Login, please try again!";and"Invalid Login!". I got the code from the url www.daniweb.com/tutorials/tutorial24148.htm it is called "Simple ASP.Net Login Page using C#" The code is as follows private void Button1_Click(object sender, System.EventArgs e) { if (Page.IsValid) { if (DBConnection(txtUserName.Text.Trim(), txtPassword.Text.Trim())) { WebForm2 wf2=new WebForm2(); WebForm2.Visible=true; } else { lblMessage.Text = "Invalid Login, please try again!"; } } } private bool DBConnection(string txtUser, string txtPass) { SqlConnection myConn = new SqlConnection("server=;database=login;user id=;password="); SqlCommand myCmd = new SqlCommand("sp_User", myConn); myCmd.CommandType = CommandType.StoredProcedure; SqlParameter objParam1; SqlParameter objParam2; SqlParameter returnParam; objParam1 = myCmd.Parameters.Add ("@NAME", SqlDbType.Char); objParam2 = myCmd.Parameters.Add ("@PASSWORD", SqlDbType.VarChar); returnParam = myCmd.Parameters.Add ("@Num_of_User", SqlDbType.Int); objParam1.Direction = ParameterDirection.Input; objParam2.Direction = ParameterDirection.Input; returnParam.Direction = ParameterDirection.ReturnValue; objParam1.Value = txtUser; objParam2.Value = txtPass; /* Label1.Text=objParam1.Value.ToString(); Label2.Text=objParam2.Value.ToString();These 2 lines that are commented outputs the label1 and label2 with the name and password i gave in run time this is just to check if this part is working fine*/ try { if (myConn.State.Equals(ConnectionState.Closed)) { myConn.Open(); myCmd.ExecuteNonQuery(); } /*the problem is that the returnParam returns 0 and not 1 and i found this out by using a textbox that stores the returnParam TextBox1.Text=returnParam.Value.ToString(); */ if ((int)returnParam.Value<1) { lblM

      M Offline
      M Offline
      macca24
      wrote on last edited by
      #2

      What do you want it to do??

      1 Reply Last reply
      0
      • S sarah_chandran

        i have a login page that accepts username and password and checks it with the value in the database,if the values match the next form is loaded otherwise error message appears. The stored procedure I used is CREATE PROCEDURE sp_User @NAME char(50),@PASSWORD varchar(50) AS SELECT COUNT(*)AS Num_of_User FROM LOGINTAB WHERE (((LOGINTAB.NAME)=@NAME) AND ((LOGINTAB.PASSWORD)=@PASSWORD)); GO The database connection does not return any error but even if i give the correct username and password i get error message""Invalid Login, please try again!";and"Invalid Login!". I got the code from the url www.daniweb.com/tutorials/tutorial24148.htm it is called "Simple ASP.Net Login Page using C#" The code is as follows private void Button1_Click(object sender, System.EventArgs e) { if (Page.IsValid) { if (DBConnection(txtUserName.Text.Trim(), txtPassword.Text.Trim())) { WebForm2 wf2=new WebForm2(); WebForm2.Visible=true; } else { lblMessage.Text = "Invalid Login, please try again!"; } } } private bool DBConnection(string txtUser, string txtPass) { SqlConnection myConn = new SqlConnection("server=;database=login;user id=;password="); SqlCommand myCmd = new SqlCommand("sp_User", myConn); myCmd.CommandType = CommandType.StoredProcedure; SqlParameter objParam1; SqlParameter objParam2; SqlParameter returnParam; objParam1 = myCmd.Parameters.Add ("@NAME", SqlDbType.Char); objParam2 = myCmd.Parameters.Add ("@PASSWORD", SqlDbType.VarChar); returnParam = myCmd.Parameters.Add ("@Num_of_User", SqlDbType.Int); objParam1.Direction = ParameterDirection.Input; objParam2.Direction = ParameterDirection.Input; returnParam.Direction = ParameterDirection.ReturnValue; objParam1.Value = txtUser; objParam2.Value = txtPass; /* Label1.Text=objParam1.Value.ToString(); Label2.Text=objParam2.Value.ToString();These 2 lines that are commented outputs the label1 and label2 with the name and password i gave in run time this is just to check if this part is working fine*/ try { if (myConn.State.Equals(ConnectionState.Closed)) { myConn.Open(); myCmd.ExecuteNonQuery(); } /*the problem is that the returnParam returns 0 and not 1 and i found this out by using a textbox that stores the returnParam TextBox1.Text=returnParam.Value.ToString(); */ if ((int)returnParam.Value<1) { lblM

        C Offline
        C Offline
        Colin Angus Mackay
        wrote on last edited by
        #3

        Your stored procedure does not return any values back through the parameters. It returns a result set of data that contains a single row with a single column. You should use ExecuteScalar() and NOT ExecuteNonQuery(). ExecuteNonQuery() is for when you don't expect any result sets. e.g.

        int result = myCmd.ExecuteNonQuery();

        result will contain the number of rows in LOGIN tab that match the supplied username and password. Does this help?


        My: Blog | Photos WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

        S 1 Reply Last reply
        0
        • C Colin Angus Mackay

          Your stored procedure does not return any values back through the parameters. It returns a result set of data that contains a single row with a single column. You should use ExecuteScalar() and NOT ExecuteNonQuery(). ExecuteNonQuery() is for when you don't expect any result sets. e.g.

          int result = myCmd.ExecuteNonQuery();

          result will contain the number of rows in LOGIN tab that match the supplied username and password. Does this help?


          My: Blog | Photos WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

          S Offline
          S Offline
          sarah_chandran
          wrote on last edited by
          #4

          HI, Even after i changed it to executescalar i am not getting the result as 1. so if u have some other idea please help. P.S. thanks for ur help.

          S 1 Reply Last reply
          0
          • S sarah_chandran

            HI, Even after i changed it to executescalar i am not getting the result as 1. so if u have some other idea please help. P.S. thanks for ur help.

            S Offline
            S Offline
            sarah_chandran
            wrote on last edited by
            #5

            hi i got the desired output i had to change the sp. crate procedure sp_user @NAME char(50), @PASSWORD varchar(50), @NO_OF_users INT OUTPUT AS SELECT @NO_OF_users = COUNT(*) FROM LOGINTAB WHERE (((LOGINTAB.NAME)=@NAME) AND ((LOGINTAB.PASSWORD)=@PASSWORD)); PRINT @NO_OF_users thanks again bye sarah

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups