ASP.NET Page /Admin/Admin.aspx.cs (C#)
1: using System;  
2: using System.Text;  
3: using System.Data;  
4: using System.Configuration;  
5: using System.Collections;  
6: using System.Web;  
7: using System.Web.Security;  
8: using System.Web.UI;  
9: using System.Web.UI.WebControls;  
10: using System.Web.UI.WebControls.WebParts;  
11: using System.Web.UI.HtmlControls;  
12: using System.Data.SqlClient;  
13: using QuiznetOnline.Data;  
14:   
15: public partial class Admin : System.Web.UI.Page  
16: {  
17:     public string tblout="";  
18:   
19:     protected void Page_Load(object sender, EventArgs e)  
20:     {  
21:         if (Session["Validated"] == null || (bool)Session["Validated"] == false)  
22:             Response.Redirect("Default.aspx");  
23:   
24:         if (!Page.IsPostBack)  
25:         {  
26:             foreach (ConnectionStringSettings conn in ConfigurationManager.ConnectionStrings)  
27:             {  
28:                 if (conn != null)  
29:                 {  
30:                     lstServers.Items.Add(new ListItem(conn.ConnectionString, conn.ConnectionString));  
31:                 }  
32:             }  
33:         }  
34:     }  
35:   
36:     protected void cmdsubmit_Click(object sender, EventArgs e)  
37:     {    
38:         SqlDataReader rdr = null;  
39:         StringBuilder str = new StringBuilder();  
40:   
41:         DataFunctions dataFunctions = DataFunctions.GetInstance();  
42:         SqlConnection sqlconnection = new SqlConnection(lstServers.SelectedValue);  
43:         sqlconnection.Open();  
44:   
45:   
46:         using (SqlCommand cmd = new SqlCommand())  
47:         {  
48:   
49:             cmd.Connection = sqlconnection;  
50:             cmd.CommandType = CommandType.Text;  
51:             cmd.CommandText = this.txtsql.Text.Replace("GO", "\r\n");  
52:             cmd.CommandTimeout = 3600;  
53:   
54:             rdr = cmd.ExecuteReader();  
55:         }  
56:   
57:         if(rdr.HasRows)  
58:         {    
59:             str.Append(tblout);  
60:             str.Append("<table border=1>");  
61:             while (rdr.Read())  
62:             {  
63:                 str.Append("<tr>");  
64:                 for (int i = 0; i < rdr.FieldCount; i++)  
65:                 {  
66:                     str.Append(string.Format("<td>{0}</td>",Convert.ToString(rdr.GetValue(i))));  
67:                 }  
68:                 str.Append("</tr>");  
69:             }  
70:             str.Append("</table>");  
71:   
72:         }  
73:         rdr.Close();  
74:   
75:         this.lblresults.Text = str.ToString();  
76:   
77:     }  
78: }  

.NET Documentation Tool is © 2002 - 2009 Winnersh Triangle Web Solutions Limited.