Dataset?
Hello,
I am developing a program and need to store some data at the application level. I do not necessarily have to store this data in a database as it is only used by the application. It will be storing multiple rows of data that I will have to query. It will only be storing approximately 10 rows of data at a time.
I could write this data to a database table, but I don't really want to deal with the overhead of having to connect and query the database.
Could I just use a Dataset and/or datatable to accomplish this?
Is there a better method of doing this. I thought of using an arraylist, but I don't think that will work like I want it to.
Any thoughts would be great.
Shivanand KamathPosted Jun 8, 2007, 12:56 PM
You can create a data table at runtime without connecting to database. Below is a example from the VS2005 help.
private void MakeDataTableAndDisplay()
{
// Create new DataTable.
DataTable table = new DataTable();
// Declare DataColumn and DataRow variables.
DataColumn column;
DataRow row;
// Create new DataColumn, set DataType, ColumnName
// and add to DataTable.
column = new DataColumn();
column.DataType = System.Type.GetType("System.Int32");
column.ColumnName = "id";
table.Columns.Add(column);
// Create second column.
column = new DataColumn();
column.DataType = Type.GetType("System.String");
column.ColumnName = "item";
table.Columns.Add(column);
// Create new DataRow objects and add to DataTable.
for(int i = 0; i < 10; i++)
{
row = table.NewRow();
row["id"] = i;
row["item"] = "item " + i;
table.Rows.Add(row);
}
// Set to DataGrid.DataSource property to the table.
dataGrid1.DataSource = table;
}