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())
{
listbody += ("<tr>");
listbody += ("<td align='center'>" + Res1["id"].ToString() + "</td>");
listbody += ("<td align='left'>" + Res1["sortname"].ToString() + "</td>");
listbody += ("</tr>");
}
listbody += ("</table>");
list2.InnerHtml = listbody;
Res1.Close();
con.Close();
}
}