日期:2010-03-15  浏览次数:20463 次

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
      // SqlConnection con = new SqlConnection("server=dbtalbe;uid=sa;pwd=sa;database=addb;");
        //con.Open();
        SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["strconn"]);
        con.Open();
        /*写入数据库
        SqlCommand cmd = new SqlCommand("INSERT INTO [Ad_Sort] ([sortname])  VALUES  ('首页广告')",con);
        cmd.ExecuteNonQuery();
        Response.Write("写入成功!");
        con.Close();
        */
        string strsql = "select * from ad_sort order by id desc";
        //读取数据
        SqlDataAdapter sda = new SqlDataAdapter(strsql, con);
        DataSet ds = new DataSet();
        sda.Fill(ds, "ad_sort");
        this.hotcommentlist.DataSource = ds;
        this.hotcommentlist.DataBind();

        //读取单个数据
        SqlDataAdapter Set = new SqlDataAdapter(strsql, con);
        DataSet Rs = new DataSet();
        Set.Fill(Rs,"ad_sort");
        //DataRowView mydrview = Rs.Tables["ad_sort"].DefaultView[0];
        this.sortname.InnerHtml = Convert.ToString(Rs.Tables["ad_sort"].DefaultView[0].Row[1]);
        /*
        SqlDataAdapter Set = new SqlDataAdapter(strsql,con);
        DataSet Rs = new DataSet();
        Set.Fill(Rs,"ad_sort");
        this.sortname.InnerHtml = Convert.ToString(Rs.Tables["ad_sort"].DefaultView[0].Row[1]);
        this.sortname.InnerHtml = Convert.ToString(Rs.Tables["ad_sort"].DefaultView[0].Row[1]);
        */

        SqlCommand cmd = new SqlCommand(strsql, con);
        SqlDataReader Res1 = cmd.ExecuteReader();
        string listbody="";
        listbody += ("<table border=0 ");
        listbody+=("<tr><td>ExecuteReader读取数据</td></tr>");
        listbody += ("<tr><th>编号</th><th>名称</th></tr>");
        while (Res1.Read())
        {
            listbod