当前位置:编程学习 > C#/ASP.NET >>

关于对BindingSoure 和BindingNavigator 的用法问题

最新在学习BindingSoure和BindingNavigator 出现了几个问题,不知道。是不是自已理解错误了。希望在这里找到解答

 

第一点

 SqlDataAdapter 的Fill方法 和Updata方法。不知道。是不是。我理解不深。我什么时候才用Fill方法 

弱类型的 DataSet 和强类型的DataSet 他们都是内存中的数据.但是。我用SqlDataAdapter连接到数据库了

还用要Fill()方法吗??这一点。可以我还不是很时白。

 

第二点:

  就是没个控件,都有DataBindings 这个,他是不是对应每一个控件。都有不同的绑定,例如,不能绑定。强类型的的库级别,的还有,表级别的内容, 他们绑定是不是。要绑定不同级点的。数据级别

 

 

 

 

这是我的试验代码。

 

下面的例子是这样的。我绑定弱类型的DataTable.可以显示出数据。但是。我绑定。强类型的Table级别。好像出错。不能绑定.

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace BindingSoureDemo.WinUi
{
    public partial class Form1 : Form
    {

        private BindingSource myBindingSource = null;
        public Form1()
        {
            myBindingSource = new BindingSource();
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            
            SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter("select * from Employees", "Data Source=.;Initial Catalog=Northwind;Integrated Security=True");

            //DataTable myTable = new DataTable();

            
            //mySqlDataAdapter.Fill(myTable);

            //myBindingSource.DataSource = myTable;

            //第一种情况 我换成弱类型的DatasSet
            DataSet myds = new DataSet();

            mySqlDataAdapter.Fill(myds);

            myBindingSource.DataSource = myds.Tables["Employees"];

            //第二情况。我换成强类型DataSet

            NorthwindDS myNorthwindDS = new NorthwindDS();

            mySqlDataAdapter.Fill(myNorthwindDS.Employees);

            myBindingSource.DataSource = myNorthwindDS.Employees;


            this.textBox1.DataBindings.Add("Text",myBindingSource,myNorthwindDS.Employees.LastNameColumn.ColumnName);

 

            //this.textBox1.DataBindings.Add("Text",myBindingSource,"FirstName");
        }

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

--------------------编程问答-------------------- myBindingSource.DataSource = myNorthwindDS;
myBindingSource.DataMember="Employees"; --------------------编程问答-------------------- 使用SqlDataAdapter可使用可断式连接,不需要程序员手动打开和关闭连接 --------------------编程问答--------------------
引用 1 楼 wangfuchong 的回复:
myBindingSource.DataSource = myNorthwindDS; 
myBindingSource.DataMember="Employees";
补充:.NET技术 ,  .NET Framework
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,