SubSonic操作

1、数据绑定

  a、dataset方式:

DataSet ds = new Select().From(Guardianf.Schema).ExecuteDataSet();

Grid1.DataSource = ds;

Grid1.DataBind();

  b、直接运用:

SqlQuery q = new Select().From<Guardianf>();

        GuardianfCollection all1 = q.ExecuteAsCollection<GuardianfCollection>();

        Grid1.DataSource = all1;

        Grid1.DataBind();

 

 

2、数据更新

 string id = TextBox9.Text;                            //根据数据表里的主键建立索引

 Guardianf model = Guardianf.FetchByID(id);            //根据索引取到的值建立一个模型

 if (model == null) return;

 model.Name = "测试";                                   //赋值

 model.Save();                                         //保存数据

 BindGrid();                                            //再绑定一次数据

 3、数据的插入

Guardianf model = new Guardianf();

model.Num = TextBox1.Text;

model.Name = TextBox2.Text;

model.Save();

 4、删除

Guardianf.Delete(Grid1.DataKeys[e.RowIndex][0]);//根据grid的行索引删除;

 

 

 

你可能感兴趣的:(BSON)