using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OracleClient;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms; namespace PDM {
    public partial class BaseInfo : Form {
        public BaseInfo() {
            InitializeComponent();
            this.tbxFilePath.Text = "d:/TestPicture/ln/";
            this.hash.Text = "d:/TestPicture/ln/";
            this.server.Text = "PDMFiles/FMSC/";
        }
        List<SpareBaseInfo> SpareBaseInfos = null;
        List<SpareBaseInfo> SpareBaseInfoDataBases = null;
        List<SpareBaseInfo> SpareBaseInfoisexist= null;         StreamWriter sw = File.AppendText(Environment.CurrentDirectory + "\\SpareBaseInfoFile.txt");
      
        private void UpdateDataBase_Click(object sender, EventArgs e) {
            try {
                var updatesql = new StringBuilder();
                SpareBaseInfos = new List<SpareBaseInfo>();
                SpareBaseInfoDataBases = new List<SpareBaseInfo>();
                SpareBaseInfoisexist = new List<SpareBaseInfo>();
                foreach(var item in Directory.GetFiles(this.tbxFilePath.Text)) {
                    var extenname = Path.GetFileName(item);
                    var name = Path.GetFileNameWithoutExtension(item);
                    if(name.Contains("#")) {
                        string[] codename = name.Split('#');
                        SpareBaseInfo sbi = new SpareBaseInfo();
                        sbi.Code = codename[0].ToString();
                        sbi.Name = codename[1].ToString();
                        sbi.FilePath = this.server.Text + extenname;
                        if(!SpareBaseInfos.Contains(sbi)) {
                            SpareBaseInfos.Add(sbi);
                        }
                        updatesql.AppendLine("update SpareBaseInfo set FilePaths='" + server.Text + extenname + "'" + "where code='" + sbi.Code + "' and name= '" + sbi.Name + "';");
                        if(!File.Exists(this.hash.Text + extenname.GetHashCode())) {
                            Directory.CreateDirectory(this.hash.Text + Math.Abs(extenname.GetHashCode()) % 1000);
                        }
                        File.Copy(item, this.hash.Text + Math.Abs(extenname.GetHashCode()) % 1000 + "/" + extenname);
                    }
                } 
                sw.Write(updatesql.ToString());
                MessageBox.Show("成功");
                sw.Close();             } catch(Exception ex) {
                
                throw ex;
            }             string sql = "select * from SpareBaseInfo where code in (";
            var Codes = SpareBaseInfos.Select(l => l.Code);
            foreach(var item in Codes) {
                sql += "'" + item + "',";
            }
            if(!string.IsNullOrEmpty(sql)) {
                sql = sql.Remove(sql.Length - 1);
            }
            sql += ")";             sql += "and name in(";
            var Names = SpareBaseInfos.Select(l => l.Name);
            foreach(var item in Names) {
                sql += "'" + item + "',";
            }
            if(!string.IsNullOrEmpty(sql)) {
                sql = sql.Remove(sql.Length - 1);
            }
            sql += ")";
            string conn = "user id=mfepc;data source=" + server.Text + ";password=mfepc";
            OracleConnection cn = new OracleConnection(conn);
            cn.Open();//要打开连接   
            string strcmd = sql;
            OracleCommand cmd = new OracleCommand(strcmd, cn);
            OracleDataReader reader = cmd.ExecuteReader();
            try {
                while(reader.Read()) {
                    var a = reader[0].ToString();
                    SpareBaseInfo sbi = new SpareBaseInfo();
                    sbi.Id = Convert.ToInt32(reader["Id"].ToString());
                    sbi.Code = reader["Code"].ToString();
                    sbi.Name = reader["Name"].ToString();
                    if(!SpareBaseInfoDataBases.Contains(sbi)) {
                        SpareBaseInfoDataBases.Add(sbi);
                    }
                }
                dataGridView1.DataSource = SpareBaseInfoDataBases;
            } finally {
                reader.Close();
            }
            var updatesql = new StringBuilder();
            try {
                if(MessageBox.Show(SpareBaseInfoDataBases.Count() + "条数据是否继续", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) {
                    updatesql.AppendLine("begin");
                    foreach(var item in SpareBaseInfoDataBases) {
                        item.FilePath = SpareBaseInfos.FirstOrDefault(l => l.Name == item.Name && l.Code == item.Code).FilePath;
                        updatesql.AppendLine("update SpareBaseInfo set FilePaths='" + item.FilePath + "'" + "where code='" + item.Code + "' and name= '" + item.Name + "';");
                    }
                    updatesql.AppendLine("end;");
                    //OracleCommand cmdupdate = new OracleCommand(updatesql.ToString(), cn);
                    //cmdupdate.ExecuteNonQuery();
                    MessageBox.Show("成功");
                }             } catch(Exception ecp) {
                throw ecp;
            }             cn.Close();
        }
    }     public class SpareBaseInfo {         private int id;         public int Id {
            get {
                return id;
            }
            set {
                id = value;
            }
        }         private string code;         public string Code {
            get {
                return code;
            }
            set {
                code = value;
            }
        }         private string name;         public string Name {
            get {
                return name;
            }
            set {
                name = value;
            }
        }         private string filePath;         public string FilePath {
            get {
                return filePath;
            }
            set {
                filePath = value;
            }
        }
        //通过DataSet来读取数据:         //创建和数据库的连接192.168.17.42/epcv2
        //OracleConnection oraCon = new OracleConnection("user id=mfepc0521;data source=192.168.17.42/mfdmstest;password=mfepc0521");
        //OracleConnection oraCon = new OracleConnection("user id=mfepc;data source=192.168.17.42/epcv2;password=mfepc");
        //OracleDataAdapter oraDap = new OracleDataAdapter("select * from SpareBaseInfo where rownum<10", oraCon);
        //DataSet ds = new DataSet();
        //oraDap.Fill(ds);
        //DataTable _table = ds.Tables[0];
        //int count = _table.Rows.Count;
        //dataGridView1.DataSource = _table;
    }
}

c# 连接oracle 读取数据的更多相关文章

  1. 连接oracle读取数据

    没怎么用过oracle,而且是在地税内网内部估计是防火墙的原因虚拟机里也连不上oracle,刚开始费了很多周折查找问题,现在又放弃使用直连数据库了,记下来以备后用吧 public class Load ...

  2. 简谈python从Oracle读取数据生成图形

    初次学习python,连接Oracle数据库,导出数据到Excel,再从Excel里面读取数据进行绘图,生成png保存出来. 1.涉及到的python模块(模块安装就不进行解释了): 1 import ...

  3. python连接oracle导出数据文件

    python连接oracle,感觉table_list文件内的表名,来卸载数据文件 主脚本: import os import logging import sys import configpars ...

  4. 水晶报表连接Oracle做数据报表笔记

    首先,新建一个水晶报表的文件,这个时候要给这个报表文件绑定一个oracle数据源, 选择右侧菜单的这个东西,选择“数据库专家”,打开之后是这么一个界面: 选择建立新连接: 这个地方最关键,也是我为什么 ...

  5. linux shell脚本连接oracle查询数据插入文件和日志文件中

    #!/bin/sh sqlplus "用户名/密码@数据库"<<EOF  或者只有一个库的 :sqlplus "用户名/密码"<<EOF ...

  6. C# Socket TcpClient 无法从传输连接中读取数据: 远程主机强迫关闭了一个现有的连接。。

    开始的代码: byte[] data = Encoding.UTF8.GetBytes(sInfo);                    tcpns.Write(data, 0,1024); 修改 ...

  7. EF6 连接Oracle 迁移数据错误解决方法

    环境:vs2015 + EF6 +ODP 数据库Oracle 11G add-migratioin 正常,但在update-database 时报如下错误: System.Runtime.Serial ...

  8. python3.4连接和读取oracle数据表

    想用python连接Oracle并查询数据表,就写了个Demo.参考了以下网址. Python学习之 cx_Oracle学习记录 一 http://my.oschina.net/bxxfighting ...

  9. C#连接Oracle数据库查询数据

    C#连接Oracle数据库可以实现许多我们需要的功能,下面介绍的是C#连接Oracle数据库查询数据的方法,如果您对C#连接Oracle数据库方面感兴趣的话,不妨一看. using System; u ...

随机推荐

  1. struts2表单验证里field-validator type值一共可以取哪些?都什么含义?

    int 整数: double 实数: date 日期: expression 两数的关系比较: email Email地址: url visitor conversion regex 正则表达式验证: ...

  2. leetcode面试准备:Multiply Strings

    1 题目 Given two numbers represented as strings, return multiplication of the numbers as a string. Not ...

  3. bzoj2326

    首先不难得出递推式f[i]=(f[i-1]*10^k+i) mod m;f[i]表示接到第i个数时的余数,k表示i的位数不难想到先按位数穷举位数,然后对于确定的位数,构造矩阵解决易得出:f[i]   ...

  4. vmware克隆centos6.5 导致 system eth0 不可用解决办法

    vim /etc/udev/rules.d/70-persistent-net.rules 可以看到eth0 eth1两个. 注释 NAME="eth0" # PCI device ...

  5. 【转】MFC中调试过程中查看输出信息 -- 不错

    原文网址:http://blog.sina.com.cn/s/blog_4e24d9c501014o39.html 笔记&&方便查阅. ~~~~~~~~~~~~~~~~~~~~~~~~ ...

  6. 51Testing招聘软件测试课程研发人员

    最近有些两三年测试工作经验的小伙伴对自己的下一个工作有些迷茫,感觉很难有技术的突破,毕竟公司不是学校,不会允许员工海阔天空的去尝试各种新的技术.现在我就送给这些好学上进的小伙伴一个礼物,51Testi ...

  7. php 错误信息配置

    display_errors = on/off错误回显,一般常用语开发模式,但是很多应用在正式环境中也忘记了关闭此选项.错误回显可以暴露出非常多的敏感信息,为攻击者下一步攻击提供便利.推荐关闭此选项. ...

  8. C# 使用Nlog记录日志到数据库 使用LogEventInfo类获取,命名空间名称、类名、方法名

    原文地址:http://dotnet.9sssd.com/csbase/art/793 [摘要]Nlog是一个很不错的.NET日志记录组件,它可以将日志输出到控件台,保存到文本,也可以很方便的记录到数 ...

  9. Calendar - SGU 115(日期判断)

    这年的开始的第一天是星期 1 代码如下: =============================================================================== ...

  10. poj 3169 Layout

    Layout Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8610   Accepted: 4147 Descriptio ...