Skip to content

Instantly share code, notes, and snippets.

@booyaa
Created September 17, 2013 11:58
Show Gist options
  • Save booyaa/6593372 to your computer and use it in GitHub Desktop.
Save booyaa/6593372 to your computer and use it in GitHub Desktop.
Create a datatable with columns and insert rows
// initialise
DataTable dt = new DataTable();
dt.TableName = "foo";

// add meta data
DataColumn col = dtColumns.Add("CustID", typeof(Int32));
DataColumn col = dtColumns.Add("Name", typeof(String));

// insert row
DataRow row = dt.NewRow();
row["CustID"] = 1;
row["Name"] = "bar";

dt.Rows.Add(row); // alt method: dt.Rows.Add(new Object[] {1, "bar"});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment