Advertisement
Guest User

Untitled

a guest
Mar 1st, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.SqlClient;
  4. using System.Linq;
  5. using System.Web;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8.  
  9. namespace Assignment_4__2_
  10. {
  11. public partial class DefualtforLogin : System.Web.UI.Page
  12. {
  13. protected void Page_Load(object sender, EventArgs e)
  14. {
  15.  
  16. }
  17. protected void submitButton_Click(object sender, EventArgs e)
  18. {
  19.  
  20. SqlConnection con = new SqlConnection();
  21. con.ConnectionString = "Data Source=itksqlexp8; ; Initial Catalog=xchenne_ConservationSchool;Integrated Security=True;Pooling=False";
  22.  
  23.  
  24. //Int32 verify;
  25. string query1 = "Select * from verification where username='" + usernameTextBox.Text + "' and password='" + passwordTextBox.Text + "' ";
  26. // SqlCommand cmd1 = new SqlCommand(query1, con);
  27. System.Data.SqlClient.SqlCommand comm = new System.Data.SqlClient.SqlCommand(query1, con);
  28.  
  29. // create a sqldatabase reader which will execute the above command to get the values from sqldatabase
  30. System.Data.SqlClient.SqlDataReader reader;
  31.  
  32. // open a connection with sqldatabase
  33. con.Open();
  34.  
  35. // execute sql command and store a return values in reade
  36. reader = comm.ExecuteReader();
  37.  
  38. // check if reader hase any value then return true otherwise return false
  39. if (reader.Read())
  40. errorLabel.Text = "Hello, " + usernameTextBox.Text;
  41.  
  42. else
  43. errorLabel.Text = "Please enter a valid username and password";
  44.  
  45. }
  46.  
  47.  
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement