Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Data.SqlClient;
  8. using System.Configuration;
  9.  
  10.  
  11. public partial class Register : System.Web.UI.Page
  12. {
  13. protected void Page_Load(object sender, EventArgs e)
  14. {
  15.  
  16. if (IsPostBack)
  17. {
  18. SqlConnection studConn = new SqlConnection(ConfigurationManager.ConnectionStrings["StudConnectionString"].ConnectionString);
  19. studConn.Open();
  20. string checkuser = "select count(*) from StudTable where-'" + TextBoxName.Text + "'";
  21. SqlCommand studCom = new SqlCommand(checkuser, studConn);
  22. int temp = Convert.ToInt32 (studCom.ExecuteScalar().ToString());
  23. studConn.Close();
  24. if (temp == 1)
  25. {
  26. Response.Write("User already exists");
  27. }
  28.  
  29. }
  30.  
  31.  
  32.  
  33. }
  34.  
  35.  
  36. protected void Button1_Click(object sender, System.EventArgs e)
  37. {
  38. try
  39. {
  40. Guid studGUID = Guid.NewGuid();
  41.  
  42. SqlConnection studConn = new SqlConnection(ConfigurationManager.ConnectionStrings["StudConnectionString"].ConnectionString);
  43. studConn.Open();
  44. string insertQuery = "insert into StudTable (ID,Name,Email,Age,Continent,School,Password) values (@ID,@name,@email,@age,@cont,@school,@pass)";
  45. SqlCommand studCom = new SqlCommand(insertQuery, studConn);
  46.  
  47. studCom.Parameters.AddWithValue("@ID", studGUID.ToString());
  48. studCom.Parameters.AddWithValue("@name", TextBoxName.Text);
  49. studCom.Parameters.AddWithValue("@email", TextBoxEmail.Text);
  50. studCom.Parameters.AddWithValue("@age", TextBoxAge.Text);
  51. studCom.Parameters.AddWithValue("@cont", DropDownCont.SelectedItem.ToString());
  52. studCom.Parameters.AddWithValue("@school", TextBoxSchool.Text);
  53. studCom.Parameters.AddWithValue("@pass", TextBoxPass.Text);
  54.  
  55. studCom.ExecuteNonQuery();
  56. Response.Redirect("Backend.aspx");
  57. Response.Write("Your Registration is Sucessful");
  58.  
  59. studConn.Close();
  60. }
  61. catch (Exception ex)
  62. {
  63. Response.Write("Error:" +ex.ToString());
  64. }
  65. }
  66. }
  67.  
  68. string checkuser = "select count(*) from StudTable where Name = @Name";
  69. SqlCommand studCom = new SqlCommand(checkuser, studConn);
  70. studCom.Parameters.AddWithValue("@Name", TextBoxName.Text);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement