My Technical Notes

Wednesday, 14 August 2013

Creating a Sample DataTable for Testing Purposes


DataTable dt = new DataTable();
dt.Columns.Add("ID", typeof(int));
dt.Columns.Add("Forename", typeof(string));
dt.Columns.Add("Surname", typeof(string));

{
    var row = dt.NewRow();
    row["ID"] = 1;
    row["Forename"] = "Tahir";
    row["Surname"] = "Hassan";
    dt.Rows.Add(row);
}

{
    var row = dt.NewRow();
    row["ID"] = 2;
    row["Forename"] = "Steven";
    row["Surname"] = "Gerrard";
    dt.Rows.Add(row);
}

{
    var row = dt.NewRow();
    row["ID"] = 3;
    row["Forename"] = "Luis";
    row["Surname"] = "Suarez";
    dt.Rows.Add(row);
}

No comments: