frazer wrote:
i have created a dataset manually.
is ther any way to have auto increment in it?
Hi frazer,
look at the following code:
private void button1_Click(object sender, System.EventArgs e)
{
//create a new DataSet
DataSet ds = new DataSet();
//add a table
DataTable dt = ds.Tables.Add();
//add a column
DataColumn dc = dt.Columns.Add("ID");
//this shall be an autoincrement column
dc.AutoIncrement = true;
dc.AutoIncrementSeed = 1;
dc.AutoIncrementStep = 1;
//another column
DataColumn dc2 = dt.Columns.Add("test");
dc2.DataType = typeof(string);
//fill the table
for (int i = 0; i < 10; i++)
{
DataRow dr = dt.NewRow();
dr["test"] = "test" + i;
dt.Rows.Add(dr);
}
//show autogenerated ids
foreach (DataRow dr in dt.Rows)
{
System.Diagnostics.Debug.WriteLine("ID: " + dr["ID"].ToString() +
", test: " + dr["test"].ToString());
}
}
Cheers
Arne Janning