从数据库中用SqlDataAdapter去的DataTable后,我把这张表绑定到了几个TextBox中,发现一个问题:
通过textBox更新的值等反应到DataTable中,但是无法更新到数据库中,但是如果绑定到dataGridView就可以
private void button1_Click(object sender, EventArgs e)
        {
            SqlDataAdapter1 = new SqlDataAdapter("select * from test",DatabaseManager.getConn());
            SqlDataAdapter1.Fill(Table1);
            textBox1.DataBindings.Add("Text",Table1,"ID");   //绑定到textBox
            textBox2.DataBindings.Add("Text", Table1, "Names");
            textBox3.DataBindings.Add("Text", Table1, "vvv");        }        private void button2_Click(object sender, EventArgs e)
        {
                  for (int i = 0; i < 3; i++)  //这里确认了,TextBox的值确实提交到了DataTable中
                Console.WriteLine(Table1.Rows[0][i].ToString());
            SqlCommandBuilder b = new SqlCommandBuilder(SqlDataAdapter1);
            SqlDataAdapter1.Update(Table1);
        }

解决方案 »

  1.   

    textBox1.DataBindings.Add("Text",myTable,"id");textBox1.DataBindings["Text"].WriteValue();myCurrencyManager = (CurrencyManager)this.BindingContext[myTable];
    myCurrencyManager.Position = 0;
    dataGrid1.DataSource=myTable;
      

  2.   

    textBox1.DataBindings["Text"].WriteValue();
    试过了,不起作用,datatable的值可以更新,但无法更新到数据库中。
    求解。
      

  3.   

    要调用row.endedit
    见这里:
    http://social.microsoft.com/forums/zh-CN/visualcshartzhchs/thread/aba01e20-56fe-4090-97c1-48074ad6b904/