using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    { 
        //连接和打开数据库
        SqlConnection conn = new SqlConnection();
        conn.ConnectionString = "server=localhost;database=mydata;integrated security=true";
        conn.Open();
        //执行SQL语句
        SqlCommand cmd = new SqlCommand();
        cmd.CommandText = "select * from  mytable2 where id=2";
        cmd.Connection = conn;
        //读取数据源
        SqlDataReader dr = cmd.ExecuteReader();
        GridView1.DataSource = dr;
        GridView1.DataBind();
        conn.Close();
 

     
    }
}