using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; using System.Configuration; using System.Data; public partial class admincheck : System.Web.UI.Page { private string _sql = string.Empty; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.d1.Visible = false; _sql = string.Format("select count(1) from log_info with(nolock) "); using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["MHLOG"].ConnectionString)) { connection.Open(); SqlCommand command = new SqlCommand(_sql, connection); command.CommandType = CommandType.Text; this.Label1.Text = command.ExecuteScalar().ToString(); } } } protected void Button1_Click(object sender, EventArgs e) { this.d1.Visible = true; _sql = string.Format("select count(1) from log_info with(nolock) where userid='{0}' ", this.TextBox1.Text.Trim()); using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["MHLOG"].ConnectionString)) { connection.Open(); SqlCommand command = new SqlCommand(_sql, connection); command.CommandType = CommandType.Text; int has = int.Parse(command.ExecuteScalar().ToString()); if (has > 0) { this.Label2.Text = "是"; } else { this.Label2.Text = "否"; } _sql = string.Format("select * from event_info with(nolock) where userid='{0}' order by createtime desc ", this.TextBox1.Text.Trim()); command.CommandText = _sql; SqlDataAdapter da = new SqlDataAdapter(command); SqlCommandBuilder scb = new SqlCommandBuilder(da); DataTable dt = new DataTable(); da.Fill(dt); this.GridView1.DataSource = dt; this.GridView1.DataBind(); } } }