我尝试制作一个 .exe 文件,该文件可以从文本文件中读取全局参数并将数据从数据库导出到 csv 文件
基本上我可以读取连接字符串并从文本文件中读取命令,但是我无法创建 csv 文件。
我的代码如下
static class CsvGenerator
{
public static string gb_Localconn = DBManager.GetParameter("ConnStr=");
public static string gb_Delimiter = DBManager.GetParameter("Delimiter=");
public static string gb_Quote = DBManager.GetParameter("Quote=");
public static string gb_QuoteType = DBManager.GetParameter("Quote_Type=");
public static string gb_CsvOutput = DBManager.GetParameter("Output_path=");
public static string gb_Prefix = DBManager.GetParameter("Output_Prefix=");
public static string gb_LogOutput = DBManager.GetParameter("Logfile_path=");
public static string gb_VesselList = DBManager.GetParameter("Vessel_list=");
private static DataTable dt;
private static int i;
public static void Main()
{
StreamReader oRead = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "Query.cfg");
string txtline = null;
string QueryName = null;
string query = null;
while (oRead.Peek() != -1)
try
{
txtline = oRead.ReadLine();
if (txtline.IndexOf(":") != -1)
{
QueryName = txtline.Substring(0, txtline.IndexOf(":"));
query = txtline.Substring(txtline.IndexOf(":") + 1, txtline.Length - QueryName.Length - 1);
query = query.Replace("|Vessels|", gb_VesselList);
MessageBox.Show(query);
{
{
dt = DBManager.DBExecuteSelect(query, gb_Localconn);
DataColumn dcol = null;
if (dt.Rows.Count > 0)
MessageBox.Show(dcol.ToString());
}
DataRow drow = null;
for (i = 0; i <= dt.Rows.Count - 1; i++)
MessageBox.Show(drow.ToString());
}
}
}
catch (InvalidCastException e)
{
Console.WriteLine("{0} Exception caught.", e);
{
}
}
}
}
有人可以帮我吗?