• 连接各种数据库语句


    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;
    using System.Data.OleDb;

    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                GridView1.DataSource = sqlconn1().Tables["donkey"].DefaultView;
                GridView1.DataBind();
                GridView2.DataSource = sqlconn2();
                GridView2.DataBind();
                GridView3.DataSource = sqlaccess();
                GridView3.DataBind();
                GridView4.DataSource = sqlexcel();
                GridView4.DataBind();
            }
        }
        public DataSet sqlconn1()
        {
            SqlConnection conn = new SqlConnection("data source=(local);database=monkey;uid=monkey;pwd=donkey");
            SqlDataAdapter database = new SqlDataAdapter("select * from donkey", conn);
            DataSet ds = new DataSet();
            conn.Open();
            database.Fill(ds, "donkey");
            conn.Close();
            return ds;
        }

        public DataTable sqlconn2()
        {
            SqlConnection conn = new SqlConnection("data source=(local);database=monkey;uid=monkey;pwd=donkey");
            SqlCommand cmd = new SqlCommand("select * from houzi", conn);
            SqlDataReader sdr = null;
            conn.Open();
            sdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
            DataTable dt = new DataTable();
            dt.Load(sdr);
            return dt;
        }

        public DataSet sqlaccess()
        {
            OleDbConnection conn = new OleDbConnection("provider=Microsoft.jet.oledb.4.0;data source=" + Server.MapPath("monkey.mdb") + "");
            OleDbDataAdapter database = new OleDbDataAdapter("select * from donkey", conn);
            DataSet ds = new DataSet();
            conn.Open();
            database.Fill(ds, "donkey");
            return ds;
        }
        public DataSet sqlexcel()
        {
            OleDbConnection conn = new OleDbConnection("provider=Microsoft.jet.oledb.4.0;data source=" + Server.MapPath("book1.xls") + ";Extended Properties=Excel 8.0");
            OleDbDataAdapter database = new OleDbDataAdapter("select * from [sheet1$]", conn);
            DataSet ds = new DataSet();
            conn.Open();
            database.Fill(ds);
            conn.Close();
            return ds;
        }
    }

    天道酬勤,厚积薄发。 君子之行,静以修身,俭以养德。 非淡泊无以明志,非宁静无以致远。 如有恒,何须三更起,半夜眠;最怕莫,三天打鱼两天晒网,竹篮打水一场空。
  • 相关阅读:
    使用require.context引入模块
    npm link的使用
    mysql 链接远程数据库
    微信错误:errcode=45015, errmsg=response out of time limit or subscription is canceled
    微信公众号发送模板消息
    VS CODE 开发php实现断点调试
    uni 蓝牙 安卓 监听不到返回数据 不可写入
    vue3.0 兄弟组件传值
    二叉查找树的实现和删除
    模块二:ES新特性与TypeScript、JS性能优化
  • 原文地址:https://www.cnblogs.com/houweidong/p/3366543.html
Copyright © 2020-2023  润新知