Thursday, February 18, 2010

Datatable/Dataview stuff

DataView dvName = dtName.DefaultView;
dvName.Sort = "Column ASC";

foreach (DataRowView drv in dvName)
{
drv["Column"]
}

DataTable dtTable = new DataTable();
foreach (DataRow dr in dtTable)
{
dr["Column"]
}


DataTable dtName = new DataTable();

DataView dvName = dtName.DefaultView;
dvName.RowFilter = "ID = " + intID
dvName.Sort = "Date DESC";

DataTable dtResults = new DataTable();
dtResults.Columns.Add(new DataColumn("ID", System.Type.GetType("System.String")));
dtResults.Columns.Add(new DataColumn("Title", System.Type.GetType("System.String")));
dtResults.Columns.Add(new DataColumn("Date", System.Type.GetType("System.DateTime")));

DataRow drResults = dtResults.NewRow();

drResults["ID"] = id;
drResults["Title"] = title;
drResults["Date"] = Convert.ToDateTime(date);

dtResults.Rows.Add(drResults);

No comments: