やってみたところ、あっさりできてしまいました。コードはこんな感じ。
private void button1_Click(object sender, EventArgs e)
{
//using System.Data.Odbc;
string csvDir = @"d:\temp";
string csvFileName = "Text1.csv";
string csvFileName2 = "Text2.csv";
//ODBC接続文字列を組み立てる
OdbcConnectionStringBuilder builder = new OdbcConnectionStringBuilder();
builder["Driver"] = "Microsoft Text Driver (*.txt; *.csv)";
builder["dbq"] = csvDir;
builder["Extension"] = "text;HDR=No;FMT=Delimited\"";
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Start();
using (OdbcConnection con = new OdbcConnection(builder.ConnectionString))
{
con.Open();
string strSQL = "SELECT T1.* FROM (" + csvFileName + " T1 INNER JOIN " + csvFileName2 + " T2 ON T1.F1=T2.F1)";
using (OdbcCommand cmd = new OdbcCommand(strSQL, con))
using (OdbcDataReader rd = cmd.ExecuteReader())
{
StringBuilder sb = new StringBuilder();
//カラム名を取得し、カンマ区切りで編集します
for (int col = 0; col < rd.FieldCount; col++)
{
sb.Append(rd.GetName(col)).Append(",");
}
sb.Remove(sb.Length - 1, 1);
System.Diagnostics.Debug.WriteLine(sb);
//データを取得しカンマ区切りで編集します
while (rd.Read())
{
sb.Length = 0;
for (int col = 0; col < rd.FieldCount; col++)
{
sb.Append(rd.GetValue(col)).Append(",");
}
sb.Remove(sb.Length - 1, 1);
System.Diagnostics.Debug.WriteLine(sb);
}
}
}
sw.Stop();
label1.Text = String.Format("完了{0:#,##0}ms", sw.ElapsedMilliseconds);
}
{
//using System.Data.Odbc;
string csvDir = @"d:\temp";
string csvFileName = "Text1.csv";
string csvFileName2 = "Text2.csv";
//ODBC接続文字列を組み立てる
OdbcConnectionStringBuilder builder = new OdbcConnectionStringBuilder();
builder["Driver"] = "Microsoft Text Driver (*.txt; *.csv)";
builder["dbq"] = csvDir;
builder["Extension"] = "text;HDR=No;FMT=Delimited\"";
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Start();
using (OdbcConnection con = new OdbcConnection(builder.ConnectionString))
{
con.Open();
string strSQL = "SELECT T1.* FROM (" + csvFileName + " T1 INNER JOIN " + csvFileName2 + " T2 ON T1.F1=T2.F1)";
using (OdbcCommand cmd = new OdbcCommand(strSQL, con))
using (OdbcDataReader rd = cmd.ExecuteReader())
{
StringBuilder sb = new StringBuilder();
//カラム名を取得し、カンマ区切りで編集します
for (int col = 0; col < rd.FieldCount; col++)
{
sb.Append(rd.GetName(col)).Append(",");
}
sb.Remove(sb.Length - 1, 1);
System.Diagnostics.Debug.WriteLine(sb);
//データを取得しカンマ区切りで編集します
while (rd.Read())
{
sb.Length = 0;
for (int col = 0; col < rd.FieldCount; col++)
{
sb.Append(rd.GetValue(col)).Append(",");
}
sb.Remove(sb.Length - 1, 1);
System.Diagnostics.Debug.WriteLine(sb);
}
}
}
sw.Stop();
label1.Text = String.Format("完了{0:#,##0}ms", sw.ElapsedMilliseconds);
}
0 件のコメント:
コメントを投稿