如删除一行,先调用数据封装类的方法实现在数据库的删除,然后再将表格内的相应行删除???
在数据库里删除掉,然后 重新绑定datagrid就行了,不需要"再将表格内的相应行删除"

解决方案 »

  1.   

    也是绑定的.只不过不是DB对DATAGRID的直接绑定.我这里的实现方法是DB==>>ARRAYLIST==>>DATATABLE==>>DATAGRID同理,修改过后更新DB,同步更新ARRAYLIST
      

  2.   

    joelbh(ILoveYou) ,重新绑定的话数据很多的话。效率回很低啊。并且实际上,datagrid的行数据DataRow不能直接对应到一个Customer,如果想使用Customer的方法的话,还要产生一个Customer对象,搞来搞去麻烦死了,怎么办呢?
      

  3.   

    可以象Duwamish 7.0 中一样,Customer类应该继承DataSet,然后在将它绑定到DataGrid。
      

  4.   

    谢谢各位朋友,我现在做信息系统,领导要求使用三层结构,并且使用了Grove(不知道各位使用过吗)工具,在使用的过程中,发现一些问题,例如送据库里有个Person_Student表,Grove生成了
    public class Person_Student 
    {
    Int32 _StuId;
    String _StuName;
    String _StuSymbol;
    Boolean _Sex;
    DateTime _Birth;
    Int32 _DepId;
    String _Tel1;
    String _Tel2;
    String _Mobile;
    String _DormId;
    String _BedNum; [KeyField("StuId")]
    public Int32 StuId
    {
    get{return this._StuId;}
    set{this._StuId=value;}
    }
    [DataField("StuName")]
    public String StuName
    {
    get{return this._StuName;}
    set{this._StuName=value;}
    }
    [DataField("StuSymbol")]
    public String StuSymbol
    {
    get{return this._StuSymbol;}
    set{this._StuSymbol=value;}
    }
    [DataField("Sex")]
    public Boolean Sex
    {
    get{return this._Sex;}
    set{this._Sex=value;}
    }
    [DataField("Birth")]
    public DateTime Birth
    {
    get{return this._Birth;}
    set{this._Birth=value;}
    }
    [DataField("DepId")]
    public Int32 DepId
    {
    get{return this._DepId;}
    set{this._DepId=value;}
    }
    [DataField("Tel1")]
    public String Tel1
    {
    get{return this._Tel1;}
    set{this._Tel1=value;}
    }
    [DataField("Tel2")]
    public String Tel2
    {
    get{return this._Tel2;}
    set{this._Tel2=value;}
    }
    [DataField("Mobile")]
    public String Mobile
    {
    get{return this._Mobile;}
    set{this._Mobile=value;}
    }
    [DataField("DormId")]
    public String DormId
    {
    get{return this._DormId;}
    set{this._DormId=value;}
    }
    [DataField("BedNum")]
    public String BedNum
    {
    get{return this._BedNum;}
    set{this._BedNum=value;}
    }
    }这样的类,另外有针对数据进行那个操作的类public class Person_StudentDB
    {
    public Person_StudentDB()
    {
    } public void Insert(Person_Student c)
    {
    IObjectOperator oo=ObjectOperatorFactory.GetObjectOperator(Global.conn);
    oo.BeginTranscation();
    try
    {
    oo.InsertObject(c);
    oo.Commit();
    }
    catch(System.Exception e)
    {
    oo.Rollback();
    throw e;
    }
    oo.Dispose();
    }
    public void Delete(Person_Student c)
    {
    IObjectOperator oo=ObjectOperatorFactory.GetObjectOperator(Global.conn);
    oo.BeginTranscation();
    try
    {
    oo.RemoveObject(c);
    oo.Commit();
    }
    catch(System.Exception e)
    {
    oo.Rollback();
    throw e;
    }
    oo.Dispose();
    }
    public void Update(Person_Student c)
    {
    IObjectOperator oo=ObjectOperatorFactory.GetObjectOperator(Global.conn);
    oo.BeginTranscation();
    try
    {
    oo.UpdateObject(c);
    oo.Commit();
    }
    catch(System.Exception e)
    {
    oo.Rollback();
    throw e;
    }
    oo.Dispose();
    }
    public EntityData SelectAll()
    {
    IObjectOperator oo=ObjectOperatorFactory.GetObjectOperator(Global.conn);
    IObjectQuery oq=oo.NewQuery(typeof(Person_Student));
    EntityData students=new EntityData();
    oq.Execute(students);
    oo.Dispose();
    return students;
    } }现在的问题,我使用public EntityData SelectAll()方法得到EntityData ( 从DataSet派生),
    将EntityData 绑定于数据表格,现在想实现双击某一行弹出一个编辑的对话框,在里面实现编辑操作
    这个编辑的对话框里面有一个Person_Student Student 的属性在对话框窗体Load事件中,可以通过使用Student.StuId,Student.StuName等获取数据库里相应的值,但是问题就在于双击数据表格某一行,我只能获取该行关联的DataRow,不能直接获取一个Person_Student
    对象,当然根据DataRow可以获取Person_Student,但是需要使用类似这样的方法Person_Student student = new Person_Student(); 
    student.StuId =(int) DataRow["StuId"];
    IObjectOperator oo = ObjectOperatorFactory.GetObjectOperator(conn);
    student=(Person_Student)oo.RetrieveObject(student.StuId,student.GetType());这样感觉用起来,特别不爽,多做了许多工作不说,而且使用了(int) DataRow["StuId"],列名“StuId”被使用,
    感觉分层没有分开阿,而且编辑完成后,调用Person_Student的保存方法(数据保存到数据库里了),数据表格
    的DataRow没有更新,还要将数据一一更新至DataRow,
    DataRow["StuId"] = student.StuId;
    .....感觉更不爽了。怎么办啊,各位难到有碰到类似的情况,
    还有,一般的开发信息系统,到底是怎么处理的呢?分不分层,怎么分层,数据绑定控件的数据绑定特性怎么使用???这个问题困扰了我很长时间,特别盼望一种优雅的处理方式,求求各位大虾了