Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 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.Web.Configuration;
  9. using System.Data;
  10.  
  11.  
  12. namespace WebApplication2
  13. {
  14. public partial class WebForm2 : System.Web.UI.Page
  15. {
  16. SqlConnection myConnection;
  17. string connString = WebConfigurationManager.ConnectionStrings["TestDBConnection"].ConnectionString;
  18. protected void Page_Load(object sender, EventArgs e)
  19. {
  20. myConnection = new SqlConnection(connString);
  21. try
  22. {
  23. myConnection.Open();
  24. Label1.Text = "<b>Server Versions:</b> " + myConnection.ServerVersion;
  25. Label1.Text += "<br /><b>Connection Is:</b>" + myConnection.State.ToString();
  26. }
  27. catch (Exception err)
  28. {
  29. Label1.Text = "Error reading database. ";
  30. Label1.Text += err.Message;
  31. }
  32. finally
  33. {
  34. myConnection.Close();
  35. Label1.Text += "<br /><b>Connection Is:</b>" + myConnection.State.ToString();
  36. }
  37. }
  38.  
  39. protected void Button1_Click(object sender, EventArgs e)
  40. {
  41. myConnection.Open();
  42. string query = "SELECT * FROM dbo.feladat2";
  43. SqlDataAdapter SDA = new SqlDataAdapter(query, myConnection);
  44. DataTable dt = new DataTable();
  45. SDA.Fill(dt);
  46. GridView1.DataSource = dt;
  47. GridView1.DataBind();
  48. myConnection.Close();
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement