0
我想在循環內使用C#創建兩個SQL表格。每個表都不同,並且其列名存儲在一個數組中。每個列名稱數組實際上是從csv文件的標題獲得的。使用C#創建SQL表格
### 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的列有:日期(日期時間),值(INT)
- 爲表2的列有:日期(日期時間),ID(VARCHAR (255)),Return(int)
請注意,這兩個表具有不同類型的不同列。 你有什麼建議如何實現這一目標?
謝謝!
什麼'header'包含完全? –
例如:表頭1的'header = {「Date」,「ID」}' – Mayou
這一切都取決於您如何確定列的類型,計算出如何獲取列名列表以及然後返回並解決表的創建。 –