·asp操作xml的实用代码 ·ASP.NET创建的XML Web服务简介
·第3课:从IIS配置数据库来组织数据
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)
{
String ConnString;
SqlConnection SqlConn;
//定义数据库连接
SqlCommand SqlCmd;
//定义SQL命令对象
DataSet ds;
//定义数据集(内存中的小型数据库)
SqlDataAdapter SqlAder;
//定义数据读取器,将数据从数据库文件读到内存中;
//SqlCommandBuilder Scbld;
ConnString = ConfigurationManager.ConnectionStrings["hsconnstr"].ConnectionString;
//连接字符串从web.config中读取
SqlConn = new SqlConnection(ConnString);
//实例化数据库连接对象
SqlCmd = new SqlCommand();
//实例化数据库连接对象
SqlAder=new SqlDataAdapter();
//实例化数据读取器
ds = new DataSet();
//实例化数据集
SqlAder.SelectCommand=new SqlCommand("select * from ad",SqlConn);
//为读取器设置SQL命令
SqlCommandBuilder Scbld = new SqlCommandBuilder(SqlAder);
//读取器执行SQL命令,数据表ad进入SqlAder
SqlAder.Fill(ds, "temp");
//读取器将ad表的内容填写到 数据集中的temp表(内存中的temp表);
Int32 i;
//定义整数
Response.Write(ds.Tables["temp"].Rows.Count.ToString());
for (i = 0; i <= (ds.Tables["temp"].Rows.Count-1); i++)
//从(第1行-下标为0-;到最后一行;循环)
{
Response.Write(ds.Tables["temp"].Rows[i]["title"].ToString()+"<br>");
//输出(本条记录title字段内容)
}
//ds.Tables["temp"].Rows[0]["title"] = "whswq";
Int32 r;
//===========以下为写入功能,可以不要==========
ds.Tables["temp"].DefaultView.Sort = "id";
//int idx=ds.Tables["temp"].DefaultView.Find(77);
//ds.Tables["temp"].Rows[0]["title"] = "strwqwq";
ds.Tables["temp"].Rows[0].Delete();
r=SqlAder.Update(ds, "temp");
//Response.Write("*******************" + r.ToString());
//==========================================
}
}
[1]
--->腾讯QQ IP数据库 2007.05.13┊附带IP数据维护工具V1.1┊珊瑚虫精简绿色特别版
--->腾讯QQ IP数据库 2007.05.06┊附带IP数据维护工具V1.1┊珊瑚虫精简绿色特别版
--->QQ IP数据库 2006.6.13 珊瑚虫精简版
--->Expedition.net V2.4
--->Kaspersky Anti-Virus Personal 2006 6.0.1.411 MP1┊附KEY[2007.07.16]┊简体中文特别版
Tags: Asp .net 数据库