ループ内で、C# を使用して 2 つの SQL テーブルを作成したいと考えています。各テーブルは異なり、その列名は配列に格納されています。列名の各配列は、実際には csv ファイルのヘッダーから取得されます。
### fnames is an array of file paths (2 csv files)
foreach string f in fnames)
{
## snip
using (StreamReader rdr = new StreamReader(f))
{
string header = read.line(); ## This is the array of table columns
}
string tab = Path.GetFileNameWithoutExtension(f);
string query = @"create table "+ tab + ..."; #I am not sure how to write the column names and types dynamically
}
想像してみろ:
- テーブル 1 の列は次のとおりです。日付 (datetime)、値 (int)
- テーブル 2 の列は、日付 (datetime)、ID (varchar(255))、戻り値 (int) です。
2 つのテーブルには、異なる型の異なる列があることに注意してください。これを達成する方法について何か提案はありますか?
ありがとうございました!