asp.net入门来一遍----数据存取
下面是对xml,access,mssql数据存取protected DataSet LoadMyPBData()
{
string sourceXml = Server.MapPath("phone.xml");
DataSet dataSet = new DataSet();
try
{
dataSet.ReadXml(sourceXml);
}
catch (Exception e)
{
dataSet = null;
}
return dataSet;
}
void Page_Load(object sender, EventArgs e)
{
if (!(Page.IsPostBack))
{
gridv.DataSource = LoadMyPBData();
gridv.DataBind();
}
}
-------------------------------
String StrSql="Data Source=127.0.0.1;Initial Catalog=dotnet;persist security info=True;user id=sa;password=1234;packet size=4096";
SqlConnection MyConn = new SqlConnection(StrSql);
MyConn.Open();
string CommSql = "select * from gbook order by id desc";
SqlDataAdapter adp = new SqlDataAdapter(CommSql,MyConn);
DataSet ds = new DataSet();
adp.Fill(ds);
DataGrid1.DataSource = ds;
DataGrid1.DataBind();
MyConn.Close();
---------------------------------------
if(!IsPostBack)
{
OleDbConnection MyConnection =new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("new.mdb"));
OleDbDataAdapter myCommand=new OleDbDataAdapter("SELECT id,typename FROM bb ",MyConnection);
DataSet ds= new DataSet();
myCommand.Fill(ds,"bb");
DropDownList2.DataSource = ds.Tables["bb"].DefaultView;
DropDownList2.DataTextField = "typename";
DropDownList2.DataValueField = "id";
DropDownList2.DataBind();
补充:Web开发 , ASP.Net ,