码迷,mamicode.com
首页 > 数据库 > 详细

access链接最原始代码,两种

时间:2016-06-05 16:57:11      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:

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.OleDb;

 

public partial class _Default : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

        yuanshi();

        //yuanshi2();

    }

 

    private void yuanshi2()

    {

        OleDbConnection conn = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=|datadirectory|db.mdb;");

        OleDbCommand comm = new OleDbCommand("select * from s", conn);

        conn.Open();

        OleDbDataReader dr = comm.ExecuteReader(CommandBehavior.CloseConnection);

        DataTable dt = new DataTable();

        dt.Load(dr);

        this.GridView1.DataSource = dt;

        this.GridView1.DataBind();

    }

 

    private void yuanshi()

    {

        OleDbConnection conn = new OleDbConnection("provider=microsoft.jet.oledb.4.0;Data source=|datadirectory|db.mdb;");

        OleDbCommand comm = new OleDbCommand("select * from s", conn);

        OleDbDataAdapter database = new OleDbDataAdapter(comm);

        DataSet ds = new DataSet();

        conn.Open();

        database.Fill(ds, "s");

        this.GridView1.DataSource = ds.Tables[0].DefaultView;

        this.GridView1.DataBind();

        conn.Close();

    }

 

}

access链接最原始代码,两种

标签:

原文地址:http://www.cnblogs.com/houweidong/p/5560992.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!