解决方案 »

  1.   

    http://developer.51cto.com/art/200907/139703.htm
      

  2.   


    前台:
     <h2>
            <asp:GridView ID="GridView1" runat="server">
            </asp:GridView>
        </h2>
    后台:
      string ConnString = "Data Source=.;Initial Catalog=data;User ID=sa;password=sa;Integrated Security=False";
            protected void Page_Load(object sender, EventArgs e)
            {
                using (SqlConnection conn = new SqlConnection(ConnString))
                {
                    SqlCommand cmd = conn.CreateCommand(); //数据库连接命令                
                    cmd.CommandText = @"select top 5 * from newtable";
                    cmd.CommandType = CommandType.Text;                
                    conn.Open();
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    DataSet ds = new DataSet();
                    da.SelectCommand = cmd;
                    da.Fill(ds, "newtable");
                    GridView1.DataSource = ds.Tables[0].DefaultView;
                    GridView1.DataBind(); 
                   
                }
            }