Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Data.SqlClient;
- using System.Web.Configuration;
- using System.Data;
- namespace WebApplication2
- {
- public partial class WebForm2 : System.Web.UI.Page
- {
- SqlConnection myConnection;
- string connString = WebConfigurationManager.ConnectionStrings["TestDBConnection"].ConnectionString;
- protected void Page_Load(object sender, EventArgs e)
- {
- myConnection = new SqlConnection(connString);
- try
- {
- myConnection.Open();
- Label1.Text = "<b>Server Versions:</b> " + myConnection.ServerVersion;
- Label1.Text += "<br /><b>Connection Is:</b>" + myConnection.State.ToString();
- }
- catch (Exception err)
- {
- Label1.Text = "Error reading database. ";
- Label1.Text += err.Message;
- }
- finally
- {
- myConnection.Close();
- Label1.Text += "<br /><b>Connection Is:</b>" + myConnection.State.ToString();
- }
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- myConnection.Open();
- string query = "SELECT * FROM dbo.feladat2";
- SqlDataAdapter SDA = new SqlDataAdapter(query, myConnection);
- DataTable dt = new DataTable();
- SDA.Fill(dt);
- GridView1.DataSource = dt;
- GridView1.DataBind();
- myConnection.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement