Skip to content

Instantly share code, notes, and snippets.

@yoshikazuendo
Created November 14, 2013 02:37
Show Gist options
  • Save yoshikazuendo/7460405 to your computer and use it in GitHub Desktop.
Save yoshikazuendo/7460405 to your computer and use it in GitHub Desktop.
DataSetでダミーデータを作ります。 たまにしか書かない分忘れっぽいのでメモです。。例は、列自体を動的に生成する方法も兼ねています。
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