Guest User

Untitled

a guest
Jun 14th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. <%@ Page Language="C#" %>
  2.  
  3. <%@ Import Namespace="System.Data.SqlClient" %>
  4.  
  5. <%
  6. SqlConnection connection = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents and Settings\Owner\My Documents\Visual Studio 2008\WebSites\WebSite1\App_Data\Database.mdf;Integrated Security=True;User Instance=True");
  7. connection.Open();
  8.  
  9. String name = Request.Params["name"];
  10.  
  11. if (name == null) {
  12. name = "steve";
  13. }
  14.  
  15. SqlCommand command = new SqlCommand("INSERT INTO test (name) VALUES ('" + name + "')", connection);
  16. command.ExecuteNonQuery();
  17.  
  18. command = new SqlCommand("SELECT * FROM test", connection);
  19. SqlDataReader reader = command.ExecuteReader();
  20.  
  21. while (reader.Read()) {
  22. Response.Write("<p>" + reader["name"] + "</p>");
  23. }
  24.  
  25. reader.Close();
  26. connection.Close();
  27. %>
Add Comment
Please, Sign In to add comment