textBox绑定数据源后,改变BindingManageBase的position值,但textBox的值未变,请各位帮忙,代码如下:
        private SqlConnection con;
    private SqlCommand comm;
    private SqlDataAdapter dataAdapter;
    private DataSet ds_ObjectInfo;    private BindingManagerBase bm;
    private void Form1_Load(object sender, System.EventArgs e)
   {
        string connstr="user id=sa;password=123;initial catalog=try;data source=JS08;";
        con=new  SqlConnection(connstr);
        comm=new SqlCommand();
        comm.Connection=con;
comm.CommandType=CommandType.StoredProcedure;
comm.CommandText="usp_AllObjectsInfo";

dataAdapter=new SqlDataAdapter(comm);
ds_ObjectInfo=new DataSet(); 
        dataAdapter.Fill(ds_ObjectInfo,"ObjectInfo");        bm=this.BindingContext[ds_ObjectInfo,"ObjectInfo"];
        textBox_Name.DataBindings.Add("Text",ds_ObjectInfo.Tables["ObjectInfo"],"ObjectName");
textBox_Religion.DataBindings.Add("Text",ds_ObjectInfo.Tables["ObjectInfo"],"Religion");


    }    private void button1_Click(object sender, System.EventArgs e)
    {
bm.Position=3;
       this.BindingContext[ds_ObjectInfo,"ObjectInfo"].Position=3;

    }

解决方案 »

  1.   

    补充一下,我想在点击 button1 时改变两个 textBox 的值
      

  2.   

    不用这么
     textBox_Name.DataBindings.Add("Text",ds_ObjectInfo.Tables["ObjectInfo"],"ObjectName
    最好用
    textbox.text="";
      

  3.   

    将这两句:
    bm=this.BindingContext[ds_ObjectInfo,"ObjectInfo"];
    bm.Position=3;都注释掉试试..
      

  4.   

    改成这样试试:
    textBox_Name.DataBindings.Add("Text",ds_ObjectInfo,"ObjectInfo.ObjectName");
    textBox_Religion.DataBindings.Add("Text",ds_ObjectInfo,"ObjectInfo.Religion");
      

  5.   

    致liujia_0421(SnowLover):
         谢谢!
         问题解决,错在这种不起眼的地方,浪费了我一天的时间,真是郁闷啊!