tabel.Rows[i];  表示每一条记录,可没见有什么“当前记录”这样的属性,求助

解决方案 »

  1.   

    private void button2_Click(object sender, System.EventArgs e)
    {

    oleDbConnection1.Open();        //  已设好连接串与SQL语句         
    oleDbDataAdapter1.Fill(dataSet1);
    DataTable table=dataSet1.Tables[0];
    dataGrid1.DataSource=table;
                               textBox1.DataBindings.Add("Text", table, "单位");  // 字段名
    }
    上面的程序是dataGrid1显示的是一个Access2000的表:“单位”
    文本编辑框textBox1与字段"单位“已绑定,
    可以发现,可以改变dataGrid1的当前记录位置,
    随着 dataGrid1当前记录的变化,textBox1字段值同步的跟着变化,
    肯定有当前记录的概念,我想!
      

  2.   

    希望大家试试,我曾经是C++BUILDER的程序员,总是用老概念跟新东西比较
      

  3.   

    这个和语言没关系,如果你使用FoxPro这种面向记录的,肯定会有“当前记录”这样的概念,反之,如果你使用的是SQL server这样面向集合的数据库,就一定不会有这样的概念。
      

  4.   

    private void GetBindingManagerBase()
    {
       /* CustomersToOrders is the RelationName of a DataRelation. 
       Therefore, the list maintained by the BindingManagerBase is the
       list of orders that belong to a specific customer in the 
       DataTable named Customers, found in DataSet1. */
       myBindingManagerBase = 
       this.BindingContext[DataSet1, "Customers.CustomersToOrders"];   // Adds delegates to the CurrentChanged and PositionChanged events.
       myBindingManagerBase.PositionChanged += 
       new EventHandler(BindingManagerBase_PositionChanged);
       myBindingManagerBase.CurrentChanged +=
       new EventHandler(BindingManagerBase_CurrentChanged);
    }private void BindingManagerBase_PositionChanged
    (object sender, EventArgs e)
    {
       // Prints the new Position of the BindingManagerBase.
       Console.Write("Position Changed: ");
       Console.WriteLine(((BindingManagerBase)sender).Position);
    }private void BindingManagerBase_CurrentChanged
    (object sender, EventArgs e)
    {
       // Prints the new value of the current object.
       Console.Write("Current Changed: ");
       Console.WriteLine(((BindingManagerBase)sender).Current);
    }private void MoveNext()
    {
       // Increments the Position property value by one.
       myBindingManagerBase.Position += 1;
    }private void MovePrevious()
    {
       // Decrements the Position property value by one.
       myBindingManagerBase.Position -= 1;
    }private void MoveFirst()
    {
       // Goes to the first row in the list.
       myBindingManagerBase.Position = 0;
    }private void MoveLast()
    {
       // Goes to the last row in the list.
       myBindingManagerBase.Position = 
       myBindingManagerBase.Count - 1;
    }
      

  5.   

    当前记录:1).
    MessageBox.Show( ((DataRowView)this.BindingContext[ds,"SysUser"].Current)[0].ToString() );2).
    MessageBox.Show( ds.Tables["SysUser"].Rows[this.BindingContext[ds,"SysUser"].Position][0].ToString() );
      

  6.   

    DataTable table=dataSet1.Tables[0];
    这时dataSet1.Tables[0];就是当前记录
    DataRow row = dataSet1.Tables[0].Rows[0]
    这时dataSet1.Tables[0].Rows[0]就是当前记录
    当前记录只是个相对的概念--我的拙见
      

  7.   

    当前记录肯定有的,  linguicheng(常伴我)  :这么复杂?
      

  8.   

    DataGrid1与TextBox移动同步,说明了有“当前记录”这个概念
      

  9.   

    当你的DataSet成为Form的成员之后,通过Form的BindingContext就可以获取当前DataRow:
    DataRow dr = ((DataRowView)this.BindingContext[this.Ds,this.Ds.Tables[0].TableName].Current).Rowthis指当前Form
    Ds是你的DataSet
      

  10.   

    drv= this.BindingContext[数据源].Current as DataRowView
    DataRow myDataRow = drv.Row;
    这个myDataRow就是当前绑定记录
      

  11.   

    BindingManageBase bmb=Control.BindingContext[dataSource,dataMember];
    DataRowView drv=bmb.Current as DataRowView;         //所管理的当前DataRowView
    int record=bmb.Posiont;                             //当前指向
      

  12.   

    这是在DataGrid中找到的一个当前位置,许多书中的例子就是以它为当前记录指示器
                MessageBox.Show(dataGrid1.CurrentCell.RowNumber.ToString());
      

  13.   

    还有一个
    dataGrid1.CurrentRowIndex +=1;DataTable估计也有一个
      

  14.   

    DataSet里面是没有当前记录这个概念的,因为它是数据的集合,而不是读取器。仅在读取器中,才可能有当前记录的概念。所以,DataReader有,因为它是读取器。DataGrid也有,因为它也封装了一个读取器。
      

  15.   

    其实这个概念说白了也很简单,在文件中,没有当前行的概念,但在TextReader中有。
    在数组中,没有当前元素的概念,但是在遍历数组时有。
      

  16.   

    为什么DataGrid移动记录时,被绑定的TextBox1同步地也变化记录,这两者的数据源
    都是DataTable对象,所以我肯定这当前记录是存在的,就在DataTable内.
      

  17.   

    怎么楼主还坚持容器里面一定要有当前记录呢?private void button2_Click(object sender, System.EventArgs e)
    {

    oleDbConnection1.Open();        //  已设好连接串与SQL语句         
    oleDbDataAdapter1.Fill(dataSet1);
    DataTable table=dataSet1.Tables[0];
    dataGrid1.DataSource=table;
                               textBox1.DataBindings.Add("Text", table, "单位");  // 字段名
    }
    在这段代码里,textBox1的DataSource是什么?没有吧,这是为什么?
    因为文本框只能绑定一个数据,所以只有DataBinding而不能有DataSource。那么DataSource是怎么来的?楼主自己好好想想吧。顺便清理一下自己的概念。
      

  18.   

    textBox1.DataBindings.Add("Text", table, "单位");  
    这一句有table参数呀
    为什么DataGrid1移动时,textBox1也跟着动的,是什么把他们牵在一起呢?
    这两者的共同点就是table呀
    再想想,欢迎讨论!               
      

  19.   

    "这是在DataGrid中找到的一个当前位置,许多书中的例子就是以它为当前记录指示器
                MessageBox.Show(dataGrid1.CurrentCell.RowNumber.ToString());"
    真有这种书吗?一定是国内作者!那是作者在骗钱,如果Row有删除,dataGrid1.CurrentCell.RowNumber还同Row号相等吗?
    int pos = this.DataGrid1.BindingContext[this.Ds,this.Ds.Tables[0].TableName].Position;
    这才是数据的当前位置,dataGrid1.CurrentCell.RowNumber只是DataGrid的当前行,不完全相等."为什么DataGrid移动记录时,被绑定的TextBox1同步地也变化记录,这两者的数据源
    都是DataTable对象,所以我肯定这当前记录是存在的,就在DataTable内."那时因为Form的CurrencyManager能够自动管理数据,保持数据同步.
    你坚持要的当前行就是它:
    DataRow dr = ((DataRowView)this.DataGrid1.BindingContext[this.Ds,this.Ds.Tables[0].TableName].Current).Row
    同我前面的代码其实是一回事,因为DataGrid继承自Form
      

  20.   

    textBox1.DataBindings[0].BindingManagerBase.Position   +=1;这一句也能使两者同步移动了,估计快明白了,
    楼上的话我再看看
      

  21.   

    你理解透CurrencyManager,你就明白了.
      

  22.   

    DataTable table=dataSet1.Tables[0];
    //      dataGrid1.BindingContext[table].Position   当前记录位置 
    //            textBox1.BindingContext[table].Position    当前记录位置 
                if (dataGrid1.BindingContext[table]==textBox1.BindingContext[table])
                    MessageBox.Show("==");
    这才明白了,两个控件绑定的table对象是相同的,所以,它们是同步的,
    这个"当前记录"是绑定管理器的属性,并不在table中,
    谢谢几位高手的邦忙,我才学C#一星期,不太了解它的数据库对象。
     
      

  23.   

    DataTable table=dataSet1.Tables[0];
    Form1.BindingContext[table].Position 这也是