zoukankan      html  css  js  c++  java
  • access调用联系

    using System;

    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)

        {

            if (!IsPostBack)

            {

                //GridView1.DataSource = bind();

                //GridView1.DataBind();

                GridView1.DataSource = bindtable();

                GridView1.DataBind();

            }

        }

     

        private DataSet bind()

        {

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

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

            OleDbDataAdapter database = new OleDbDataAdapter(comm);

            DataSet ds = new DataSet();

            conn.Open();

            database.Fill(ds);

            return ds;

        }

     

        private DataTable bindtable()

        {

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

            conn.Open();

            OleDbCommand cmd = new OleDbCommand("select * from pa order by id desc", conn);

            OleDbDataReader sdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);

            DataTable dt = new DataTable();

            dt.Load(sdr);

            return dt;

            conn.Close();

        }

     

        protected void Button1_Click(object sender, EventArgs e)

        {

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

            conn.Open();

            OleDbCommand cmd = new OleDbCommand("insert into pa(xxmc) values('" + TextBox1.Text + "')", conn);

            cmd.ExecuteNonQuery();

            OleDbCommand comm = new OleDbCommand("select * from pa order by id desc",conn);

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

            DataTable dt = new DataTable();

            dt.Load(sdr);

            GridView1.DataSource = dt;

            GridView1.DataBind();

            conn.Close();

        }

    }

    天道酬勤,厚积薄发。 君子之行,静以修身,俭以养德。 非淡泊无以明志,非宁静无以致远。 如有恒,何须三更起,半夜眠;最怕莫,三天打鱼两天晒网,竹篮打水一场空。
  • 相关阅读:
    《炒股的智慧》
    python函数初识
    python文件操作
    python 表 字典 数据补充
    python深浅copy,is,id
    python列表字典小练习
    python列表字典练习
    python for/range练习
    python列表练习
    python每日小练习
  • 原文地址:https://www.cnblogs.com/houweidong/p/4185052.html
Copyright © 2011-2022 走看看