BindingSoure和BindingNavigator 用法实例

 private BindingSource myBindingSource = new BindingSource();
        OracleConnection conn = new OracleConnection("Data Source=xxx;Persist Security Info=True;User ID=xxx;Password=xxx");

        private void Form1_Load(object sender, EventArgs e)
        {
          
            string sql3 = "select * from xxxx ";
            OracleCommand cmd3 = new OracleCommand(sql3, conn);
            OracleDataAdapter oda = new OracleDataAdapter(cmd3);
            DataSet ds = new DataSet();
            oda.Fill(ds);
            myBindingSource.DataSource = ds.Tables[0];              //绑定数据源
            this.bindingNavigator1.BindingSource = myBindingSource; //数据源跟bindingNavigator1控件相连

            this.dataGridView1.DataSource = myBindingSource;        //数据源跟dataGridView1控件相连


            this.textBox1.DataBindings.Add("Text", myBindingSource, "IP");//数据源跟textBox1控件相连


        }

        private void button1_Click(object sender, EventArgs e)
        {
            myBindingSource.MoveNext();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            myBindingSource.MovePrevious();
        }

posted on 2009-03-28 21:00  一粒沙  阅读(1938)  评论(0编辑  收藏  举报