Created
November 14, 2013 02:37
-
-
Save yoshikazuendo/7460405 to your computer and use it in GitHub Desktop.
DataSetでダミーデータを作ります。
たまにしか書かない分忘れっぽいのでメモです。。例は、列自体を動的に生成する方法も兼ねています。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ds = new DataSet(); | |
var table = new DataTable(); | |
table.Columns.Add("No"); | |
table.Columns.Add("RecpDate"); | |
table.Columns.Add("RecpNo"); | |
string columnName = "Column"; | |
for (int i = 0; i < 100; i++) { | |
table.Columns.Add(columnName + i.ToString()); | |
} | |
for (int i = 0; i < 15; i++) { | |
var newRow = table.NewRow(); | |
newRow["No"] = i.ToString(); | |
newRow["RecpDate"] = "yyyyMMdd"; | |
newRow["RecpNo"] = i.ToString("00000"); | |
for (int j = 0; j < 100; j++) { | |
newRow[columnName + j.ToString()] = columnName + j.ToString(); | |
} | |
table.Rows.Add(newRow); | |
} | |
ds.Tables.Add(table); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment