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 ();
/* Write to the database
SqlCommand cmd = new SqlCommand ("INSERT into [Ad_sort] ([Sortname]) VALUES (' Home ads ')", con);
Cmd. ExecuteNonQuery ();
Response.Write ("Write succeeded!") ");
Con. Close ();
*/
String strSQL = "SELECT * from Ad_sort ORDER by id DESC";
Reading data
SqlDataAdapter SDA = new SqlDataAdapter (strSQL, con);
DataSet ds = new DataSet ();
Sda. Fill (ds, "Ad_sort");
This.hotcommentlist.DataSource = ds;
This.hotcommentlist.DataBind ();
Read single data
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 read Data </td></tr>");
Listbody + + ("<tr><th> number </th><th> name </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 ();
}
}