1. 程式人生 > >省廳報件7.0 讀取mdb 生成xml 文件

省廳報件7.0 讀取mdb 生成xml 文件

tel long {0} datetime fda string console .get exceptio

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{

try
{

var address = @"C:\Users\Administrator\Downloads\JSYD (12).mdb";
String str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=‘" + address + "‘";
var con = new OleDbConnection(str);
con.Open();
OleDbCommand cmd = con.CreateCommand();

//獲得數據

OleDbDataAdapter dagroup = new OleDbDataAdapter("select * from T_ZD_TYPE ", con);
DataSet dsgroup = new DataSet();
dagroup.Fill(dsgroup, "ddgroup");
var dt = dsgroup.Tables[0];
var str1 = "";
for (int i = 0; i < dt.Rows.Count; i++)

{
var type = dt.Rows[i]["TYPE"];
var mc = dt.Rows[i]["MC"];
var dm = dt.Rows[i]["DM"];
var typeBZ = dt.Rows[i]["TYPEBZ"];
str1 += string.Format("<dict name =‘‘ key = ‘{0}‘ value = ‘{1}‘ type =‘{2}‘ desc = ‘{3}‘ />\r\n", dm, mc, type, typeBZ);
}
WriteLogFile(str1);
con.Close();
con.Dispose();

}

catch (Exception ex)
{
//con.Close();
//con.Dispose();
throw ex;
}

}

/**/
/// <summary>
/// 寫入日誌文件
/// </summary>
/// <param name="input"></param>
public static void WriteLogFile(string input)
{
/**/
///指定日誌文件的目錄
string fname = Directory.GetCurrentDirectory() + "\\LogFile.txt";
/**/
///定義文件信息對象

FileInfo finfo = new FileInfo(fname);

if (!finfo.Exists)
{
FileStream fs;
fs = File.Create(fname);
fs.Close();
finfo = new FileInfo(fname);
}

/**/
///判斷文件是否存在以及是否大於2K
if (finfo.Length > 1024 * 1024 * 10)
{
/**/
///文件超過10MB則重命名
File.Move(Directory.GetCurrentDirectory() + "\\LogFile.txt", Directory.GetCurrentDirectory() + DateTime.Now.TimeOfDay + "\\LogFile.txt");
/**/
///刪除該文件
//finfo.Delete();
}
//finfo.AppendText();
/**/
///創建只寫文件流

using (FileStream fs = finfo.OpenWrite())
{
/**/
///根據上面創建的文件流創建寫數據流
StreamWriter w = new StreamWriter(fs);

/**/
///設置寫數據流的起始位置為文件流的末尾
w.BaseStream.Seek(0, SeekOrigin.End);

/**/
///寫入“Log Entry : ”
w.Write("\n\rLog Entry : ");

/**/
///寫入當前系統時間並換行
w.Write("{0} {1} \n\r", DateTime.Now.ToLongTimeString(),
DateTime.Now.ToLongDateString());

/**/
///寫入日誌內容並換行
w.Write(input + "\n\r");

/**/
///寫入------------------------------------“並換行
w.Write("------------------------------------\n\r");

/**/
///清空緩沖區內容,並把緩沖區內容寫入基礎流
w.Flush();

/**/
///關閉寫數據流
w.Close();
}

}
}
}

省廳報件7.0 讀取mdb 生成xml 文件