c# 连接oracle 读取数据
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 读取数据的更多相关文章
- 连接oracle读取数据
没怎么用过oracle,而且是在地税内网内部估计是防火墙的原因虚拟机里也连不上oracle,刚开始费了很多周折查找问题,现在又放弃使用直连数据库了,记下来以备后用吧 public class Load ...
- 简谈python从Oracle读取数据生成图形
初次学习python,连接Oracle数据库,导出数据到Excel,再从Excel里面读取数据进行绘图,生成png保存出来. 1.涉及到的python模块(模块安装就不进行解释了): 1 import ...
- python连接oracle导出数据文件
python连接oracle,感觉table_list文件内的表名,来卸载数据文件 主脚本: import os import logging import sys import configpars ...
- 水晶报表连接Oracle做数据报表笔记
首先,新建一个水晶报表的文件,这个时候要给这个报表文件绑定一个oracle数据源, 选择右侧菜单的这个东西,选择“数据库专家”,打开之后是这么一个界面: 选择建立新连接: 这个地方最关键,也是我为什么 ...
- linux shell脚本连接oracle查询数据插入文件和日志文件中
#!/bin/sh sqlplus "用户名/密码@数据库"<<EOF 或者只有一个库的 :sqlplus "用户名/密码"<<EOF ...
- C# Socket TcpClient 无法从传输连接中读取数据: 远程主机强迫关闭了一个现有的连接。。
开始的代码: byte[] data = Encoding.UTF8.GetBytes(sInfo); tcpns.Write(data, 0,1024); 修改 ...
- EF6 连接Oracle 迁移数据错误解决方法
环境:vs2015 + EF6 +ODP 数据库Oracle 11G add-migratioin 正常,但在update-database 时报如下错误: System.Runtime.Serial ...
- python3.4连接和读取oracle数据表
想用python连接Oracle并查询数据表,就写了个Demo.参考了以下网址. Python学习之 cx_Oracle学习记录 一 http://my.oschina.net/bxxfighting ...
- C#连接Oracle数据库查询数据
C#连接Oracle数据库可以实现许多我们需要的功能,下面介绍的是C#连接Oracle数据库查询数据的方法,如果您对C#连接Oracle数据库方面感兴趣的话,不妨一看. using System; u ...
随机推荐
- java中的日期格式
时间日期标识符: yyyy:年 MM:月 dd:日 hh:~12小时制(-) HH:24小时制(-) mm:分 ss:秒 S:毫秒 E:星期几 D:一年中的第几天 F:一月中的第几个星期(会把这个月总 ...
- JS仿淘宝详情页菜单条智能定位效果
类似于淘宝详情页菜单条智能定位 对于每个人来说并不陌生!如下截图所示:红色框的那部分! 基本原理: 是用JS侦听滚动事件,当页面的滚动距离(页面滚动的高度)大于或者等于 "对象"( ...
- (转载)在vmware中简单配置vsftpd服务器
(转载)http://blog.chinaunix.net/uid-7453676-id-2625582.html 分类: LINUX 一 试验的前期环境搭建 系统环境:Fedora 2 软件 ...
- WIA设备批量扫描
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- Hibernate(六)一对一双向关联映射
在上次的博文Hibernate从入门到精通(五)一对一单向关联映射中我们讲解了一下一对一单向关联映射, 这次我们继续讲解一下与之对应的一对一双向关联映射. 一对一双向关联 与一对一单向关联映 射所不同 ...
- ASP.net:截取固定长度字符串显示在页面,多余部分显示为省略号
方法一: public static string GetString(string str, int length) { int i = 0, j = 0; foreach(char chr in ...
- MobaSSH SSH server for Windows - Download Home Edition
MobaSSH SSH server for Windows - Download Home Edition undefined
- 10 个用于收集硬件信息的 Linux 命令
知道自己的Linux系统运行在什么样的硬件组件上总是好的,因为如果涉及到在系统上安装软件包和驱动程序的话,这将有助于你处理兼容性问题. 因此,下面我们将给出一些非常有用的命令,它们可以帮助你提取你的L ...
- C语言中数据类型转换的学习
1. 整型和枚举类型数据的转换 测试代码如下: #include <stdio.h> typedef enum _E_TYPE_T { E_TYPE_1 = -1, E_T ...
- C#添加资源的两种方式
1.粘贴到项目Properties中的Resources.resx中 base.m_bitmap = Properties.Resources.MeasuredisTool; 2.添加已有资源中的bm ...