python dataset用法_dataset 用法(2)

1、为DataTable添加列

(1)添加列

DataTable  tbl = ds.Tables.Add("User");

DataColumn col =tbl.Columns.Add("UserID",typeof(int));

col.AllowDBNull = false;

col.MaxLength = 6;

col.Unique = true;

tbl.PrimaryKey = new DataColumn[]{tbl.Columns["UserID"]};

当设置主键时,AllowDBNull自动设置为False;

(2)添加自增列

DataSet ds = new DataSet();

DataTable tbl = ds.Tables.Add("User");

DataColumn col = tbl.Columns.Add("UserID",typeof(int));

col.AutoIncrement = true;

col.AutoIncrementSeed = -1;

col.AutoIncrementStep = -1;

col.ReadOnly = true;

2、修改DataTable中的数据

(1)添加数据行

DataRow row = ds.Tables["User"].NewRow();

row["UserID"] = "123456";

ds.Tables["User"].Rows.Add(row);

你可能感兴趣的:(python,dataset用法)