C#连接远程oracle字符串,返回操作时间代码

C#连接远程oracle字符串,返回操作时间代码,这些代码可以直接运行哟!


注:using System.Data.OracleClient; 需要在项目右键点击,选择 '添加引用' ,在 .NET 中选择该项..

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OracleClient;
namespace Appneu
{
    public partial class FrmCnfTable : Form
    {
        public FrmCnfTable()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            #region 从region到endregion是手工写的。别的都是系统自动生成的

            string constring = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.3.120) (PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=orcl)));Persist Security Info=True;User Id=wangjj; Password=wangjj";
            OracleConnection conn = new OracleConnection(constring);//进行连接         

            try
            {
                conn.Open();//打开指定的连接                 
                OracleCommand com = conn.CreateCommand();
                com.CommandText = "Select Sysdate From dual ";//写好想执行的Sql语句                 
                OracleDataReader odr = com.ExecuteReader();
                while (odr.Read())//读取数据,如果返回为false的话,就说明到记录集的尾部了                  
                {
                    label1.Text = "远程数据库时间:"+odr.GetOracleDateTime(0).ToString();//获得远程数据库时间
                }
                odr.Close();//关闭reader.这是一定要写的
            }
            catch
            {
                MessageBox.Show("erro");//如果发生异常,则提示出错            
            }
            finally
            {
                conn.Close();//关闭打开的连接            
            }
            #endregion

        }
    }
}

 

本文来自: IT知道网(http://www.itwis.com) 详细出处参考:http://www.itwis.com/html/net/c/20100629/8639.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值