请教.net(C#)数据导入导出的问题

yifeiyuann 2005-09-18 11:04:42
请问如何将.txt文件的数据通过.net程序,导入到Oracle数据库中?
然后将数据导出到.txt文件中。
数据之间已逗号分隔。
有关导入导出的都可以。
...全文
215 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
yifeiyuann 2005-09-23
  • 打赏
  • 举报
回复
回楼上,thanks
northdevil 2005-09-23
  • 打赏
  • 举报
回复
导入:
void Import()
{
Encoding fileEncoding = TxtFileEncoding.GetEncoding(path,Encoding.GetEncoding("GB2312"));//确定编码
StreamReader sr = new StreamReader(path,fileEncoding); //读取文件到流中
sr.BaseStream.Seek(0,SeekOrigin.Begin);//Seek到文件开始处

do
{
string strLine = sr.ReadLine();//读取一行
if(strLine != null)
{
string[] values = strLine.Split(',');//通过约定的分隔符(这里是","号)把这一行字符串分隔为数组,每一个元素就是对应列的值

string sql = "insert into table1 values('" + values[0] + "','" + values[1] + "')";//构造SQL语句

ExecuteSQL(titles,values,importDate,user); //执行SQL语句
strLine = sr.ReadLine();
}
}while(strLine != null);

sr.Close();
}

导出:
void Export()
{
StreamWriter sw = File.CreateText(fileName);//创建文件
sw.BaseStream.Seek(0,SeekOrigin.Begin);//Seek到文件开始处
IDataReader reader = GetRecord();//获得数据库中记录
while(reader.Read()) //遍历每条记录
{
string col1 = reader[0] as string;
string col2 = reader[1] as string;
string values = col1 + "," + col2; //生成文件中的每一行
sw.WriteLine(values); //写入该行
}
reader.Close();
sw.Flush();
sw.Close();
}
zhaoliang_chen 2005-09-19
  • 打赏
  • 举报
回复
mark
我不懂电脑 2005-09-19
  • 打赏
  • 举报
回复
使用 oracle 的工具,export file
beijingbeerman 2005-09-19
  • 打赏
  • 举报
回复
可以导到DataSet中然后转成xml
bflovesnow 2005-09-19
  • 打赏
  • 举报
回复
使用 oracle 的工具,名字是什么给忘了 -_-
自由程序员 2005-09-19
  • 打赏
  • 举报
回复
关注&帮顶

111,119

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧