Advertisement
Guest User

Untitled

a guest
May 30th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. <%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="UW_Final_project.WebForm2" %>
  2.  
  3. <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
  4. <script runat="server">
  5. protected void btnLogin_Click(object sender, EventArgs e){
  6. System.Data.SqlClient.SqlConnection objCon = new System.Data.SqlClient.SqlConnection();
  7. try
  8. {
  9. // define connection parameters to SQLServer
  10. objCon.ConnectionString = @"Data Source=.;Initial Catalog=AdvWebDevProject;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework";
  11.  
  12. System.Data.SqlClient.SqlCommand objCmd = new System.Data.SqlClient.SqlCommand();
  13. objCmd.Connection = objCon;
  14. objCmd.CommandType = System.Data.CommandType.StoredProcedure;
  15. objCmd.CommandText = "pSelLoginIdByLoginAndPassword";
  16.  
  17. // input parameter @StudentLogin
  18. System.Data.SqlClient.SqlParameter objP1 = new System.Data.SqlClient.SqlParameter();
  19. objP1.Direction = System.Data.ParameterDirection.Input;
  20. objP1.DbType = System.Data.DbType.String;
  21. objP1.Size = 50;
  22. objP1.ParameterName = "@StudentLogin";
  23. objP1.Value = tbUsername.Text;
  24. objCmd.Parameters.Add(objP1);
  25.  
  26. // input parameter @StudentPassword
  27. System.Data.SqlClient.SqlParameter objP2 = new System.Data.SqlClient.SqlParameter();
  28. objP2.Direction = System.Data.ParameterDirection.Input;
  29. objP2.DbType = System.Data.DbType.String;
  30. objP2.Size = 50;
  31. objP2.ParameterName = "@StudentPassword";
  32. objP2.Value = tbPassword.Text;
  33. objCmd.Parameters.Add(objP2);
  34.  
  35. // Output Parameters
  36. System.Data.SqlClient.SqlParameter objP3 = new System.Data.SqlClient.SqlParameter();
  37. objP3.ParameterName = "@StudentId";
  38. objP3.SqlDbType = System.Data.SqlDbType.Int;
  39. objP3.Direction = System.Data.ParameterDirection.Output;
  40. objCmd.Parameters.Add(objP3);
  41.  
  42. // open the connection and execute SQL command
  43. objCon.Open();
  44. objCmd.ExecuteNonQuery();
  45. string StudentId = objP3.Value.ToString();
  46. Response.Write("Your Id = " + StudentId);
  47.  
  48. // user feedback
  49. Response.Write("Your account has been created");
  50. HttpCookie cookie = new HttpCookie("StudentID");
  51. cookie["ID"] = StudentId;
  52. Response.Cookies.Add(cookie);
  53.  
  54. }
  55. finally { objCon.Close(); } // clean up
  56. }
  57. </script>
  58. </asp:Content>
  59. <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
  60. <label>Username: </label>
  61. <asp:TextBox ID="tbUsername" runat="server"></asp:TextBox><br /><br />
  62. <label>Password: </label>
  63. <asp:TextBox ID="tbPassword" runat="server"></asp:TextBox><br /><br />
  64.  
  65. <asp:Button ID="btnSubmitRequest" runat="server" Text="Request Access" OnClick="btnLogin_Click" /><br />
  66. </asp:Content>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement