惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Visual Studio Blog
阮一峰的网络日志
阮一峰的网络日志
博客园_首页
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Last Week in AI
Last Week in AI
罗磊的独立博客
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 【当耐特】
T
Tailwind CSS Blog
美团技术团队
Y
Y Combinator Blog
I
InfoQ
C
Check Point Blog
Microsoft Security Blog
Microsoft Security Blog
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
博客园 - Franky
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
G
GRAHAM CLULEY
爱范儿
爱范儿
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Google DeepMind News
Google DeepMind News
F
Fortinet All Blogs
A
Arctic Wolf
Hugging Face - Blog
Hugging Face - Blog
S
Security Affairs
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
小众软件
小众软件
云风的 BLOG
云风的 BLOG
酷 壳 – CoolShell
酷 壳 – CoolShell
Recent Announcements
Recent Announcements
H
Heimdal Security Blog
博客园 - 司徒正美
Latest news
Latest news
H
Hacker News: Front Page
H
Help Net Security
Know Your Adversary
Know Your Adversary
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
S
Secure Thoughts
AWS News Blog
AWS News Blog
V
Vulnerabilities – Threatpost
NISL@THU
NISL@THU
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LangChain Blog
The GitHub Blog
The GitHub Blog
有赞技术团队
有赞技术团队
The Cloudflare Blog
I
Intezer
N
News and Events Feed by Topic

博客园 - 寒天飞雪

项目中用到Excel上传到Sql数据库 转载: 房贷的两种还款方式介绍 RFC访问SAP(C#) VB.net连接SAP实例(vb.net写法) VB.net连接SAP实例 - 寒天飞雪 - 博客园 Winform 树型菜单例子 - 寒天飞雪 - 博客园 介绍: MRP和MPS 收藏: SQLServer的存储结构 转载: 正则表达式介绍 转载: ReportViewer : RDLC自定义工具栏 C#调用iTextSharp组件生成PDF文件, 在VS2005下已经调试通过! SQLSERVER 2005 BI的帮助文档说明: 9.2 定义和浏览翻译 9.1 定义和浏览透视 8.1 定义操作 7.1 定义关键指标KPI 6.3使用脚本命令定义作用域分配 6.2 定义命名集 6.1 定义计算成员
.net 连接ORACLE 数据库的例子 - 寒天飞雪
寒天飞雪 · 2008-08-04 · via 博客园 - 寒天飞雪

利用 System.Data.OracleClient.Dll 的组件进行连接:

首先配置WebConfig 文件;

<connectionStrings>
     <add name="oracleconn" connectionString="Data Source="";User ID=ryq;Password=123456" providerName="System.Data.OracleClient"/>
  </connectionStrings>

然后添加System.Data.OracleClient.Dll  的引用才可以在页面中写代码using System.Data.OracleClient;

System.Data.OracleClient.Dll  常用的类:

System.Data.OracleClient.OracleConnection;

System.Data.OracleClient.OracleConnectionStringBuilder;

System.Data.OracleClient.OracleCommand;

System.Data.OracleClient.OracleCommandBuilder;

System.Data.OracleClient.OracleDataAdapter;

System.Data.OracleClient.OracleDataReader;

System.Data.OracleClient.OracleTransaction;

System.Data.OracleClient.OraclePerameter;

System.Data.OracleClient.OracleString;

System.Data.OracleClient.OracleType;

//前台显示

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Oracle连接数据测试</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <br />
        显示数据测试:<asp:Button ID="Btn_Search" runat="server" OnClick="Btn_Search_Click" Text="查询"
            Width="64px" /><br />
        <br />
        <br />
        <br />
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Height="184px"
            Width="872px">
            <Columns>
                <asp:BoundField DataField="emporium_id" HeaderText="客户编号" SortExpression="客户编号" />
                <asp:BoundField DataField="item_no" HeaderText="项次" SortExpression="项次" />
                <asp:BoundField DataField="recipients" HeaderText="联系地址" SortExpression="联系地址" />
                <asp:BoundField DataField="delive_address" HeaderText="送货地址" SortExpression="送货地址" />
            </Columns>
        </asp:GridView>
   
    </div>
        <asp:Label ID="Label1" runat="server" Height="24px" Text="Label" Width="688px"></asp:Label>
    </form>
</body>
</html>

//后台代码实现:

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.OracleClient; //要引用的类库


public partial class _Default : System.Web.UI.Page
{
    public System.Data.OracleClient.OracleConnection objConn;  //声明一个OracleConnection对象
    public System.Data.OracleClient.OracleCommand objCmd;  //声明一个OracleCommand对象
    public System.Data.OracleClient.OracleDataAdapter objAdp; //数据库适配器

    public System.Data.DataSet dset; //DataSet 用于数据填充
       //页面加载
    protected void Page_Load(object sender, EventArgs e)
    {
        Label1.Text = "";
        string strconn = System.Configuration.ConfigurationManager.ConnectionStrings["oracleconn"].ConnectionString;

        objConn = new OracleConnection(strconn);
    }
    //查询按钮设计
    protected void Btn_Search_Click(object sender, EventArgs e)
    {
        try
        {
            string StrSql = "select * from pub_address";
            objConn.Open();
            objCmd = new OracleCommand(StrSql, objConn);
            objAdp = new OracleDataAdapter(objCmd);
            dset = new DataSet();
            objAdp.Fill(dset);
            objConn.Close();
            GridView1.DataSource = dset;
            GridView1.DataBind();
        }
        catch(Exception ex)
        {
            Label1.Text = ex.ToString();
            return;
         }
    }
}

//以上简单实现从Oracle 中查询数据显示GridView 中, 当然重要的是数据库如何连接的部分。