文档库 最新最全的文档下载
当前位置:文档库 › DataTable,DataView和DataGrid中一些讲解

DataTable,DataView和DataGrid中一些讲解

DataTable,DataView和DataGrid中一些讲解
DataTable,DataView和DataGrid中一些讲解

DataTable,DataView和DataGrid中一些容易混淆的概念

一、DataTable

DataTable表示内存中数据的一个表,它完全是在内存中的一个独立存在,包含了这张表的全部信息。DataTable可以是从通过连接从数据库中读取出来形成的一个表,一旦将内容读到DataTable中,此DataTable就可以跟数据源断开而独立存在;也可以是完全由程序自己通过代码来建立的一个表。

◆ DataColumn

一个表是由行和列组成的一个两维的结构。表的结构是由DataColumn 对象的集合组成,DataColumn 对象集合可由DataTable.Columns 属性中能获取到,通过定义每一列的数据类型来确定表的架构,类似数据库中定义表。定义完表的结构就可以根据结构来生成DataRow,用DataTable.NewRow()方法来生成此DataTable结构的新行。

一个DataTable是由DataRow的集合组成的, DataRow的集合这个可以由DataTable.Rows 属性来访问。

DataTable还可以通过现有的列用Expression 属性的表达式创建一些列。

1、创建计算出的列

比如:已经有了一个表结构,表中有一个DataColumn的集合,其中有一个叫UnitPrice的列,你可以新建一个DataColumn,设置好ColumnName,再设置此列的表达式,DataColumn.Expression = "UnitPrice * 0.086",这个列的值就是名字为UnitPrice的列计算出来的,在创建表达式时,使用 ColumnName 属性来引用列。

2、第二个用途是创建聚合列

聚合列聚合通常沿着关系执行(有关关系的描述见下面DataRelation部分),如果order表有名为 detail 的子表,两个表之间通过order.orderid和detail.orderid两个列建立一个关系 DataRelation 对象名为“order2detail”,在主表order中就可以建立一个聚合列,将计算每个order在detail表中含有的所有item的价格的和:DataColumn.Expression = “sum(child(order2detail).price)",child(order2detail)表示通过关系order2detail联系到的子表,child(order2detail).price就表示子表的price列。

◆ DataRow

DataRow对象没有直接在代码中使用的构造函数,一般是从具有一定结构的DataTable用NewRow()方法来新建一个DataRow对象。一个DataRow根据其是独立的,还是属于某个DataTable,是否修改过,是否被DataTable删除等等不同的情况有不同的状态,由DataRow.RowState属性公开,如下表:

成员名称说明

Added 该行已添加到 DataRowCollection 中,AcceptChanges 尚未调用。Deleted 该行已通过 DataRow 的 Delete 方法被删除。Deleted 该行已通过 DataRow 的 Delete 方法被删除。

该行已被创建,但不属于任何 DataRowCollection。DataRow 在以下情况下立即处于此状态:创建之后添加到集合中之前;或从Detached

集合中移除之后。

Modified 该行已被修改,AcceptChanges 尚未调用。

Unchanged 该行自上次调用 AcceptChanges 以来尚未更改。

一个DataRow对象刚被创建之后其状态是Detached,是孤立的一个存在,所以建立了DataRow之后在DataRow中的单元填充了数据

后还要通过DataTable.Rows.Add(DataRow)方法将此DataRow添加到DataTable,DataRow添加到DataTable后, 这个DataRow的状

态就转变为Added。当修改了这个DataRow后,这个DataRow状态转为Modified,当用DataRow.Delete()方法删除DataRow后,DataRow状态将转为Deleted,不过此行还存在在DataTable中的,只是状态改变了,这时用DataTable.Rows.Count查看行数,跟删除

前是一样的。只有在调用了DataTable.Remove(DataRow)方法后,此DataRow才被从DataTable移除,状态也回复到Detached孤立状

态。

一旦调用了DataTable.AcceptChanges()方法后,所有的行将根据不同的状态做不同的处理,Added、Modified、Unchanged将保留当

前值,Deleted的行将从DataTable中移除,最后所有的行的状态都置为Unchanged。当DataTable是从DataAdapter.Fill(DataSet,DataTable)方法填充而形成的,Fill()方法将自动调用AcceptChanges()方法,将DataTable的行状态都置为Unchanged。并且,

如果Fill方法中指定的那个DataTable在要填充的那个DataSet不存在时,会生成一个跟数据源表同样的结构的DataTable并填充数据。

◆ DataRelation

表示两个 DataTable 对象之间的父/子关系。可以类比于数据库中的表之间的关系,父表相当于关系列为主键的表,子表相当于关系列为

外键的表。DataRelation 构造函数一般为:DataRelation(String, DataColumn, DataColumn) ,string为关系名,第一个DataColumn为

建立关系的父表列,第二个DataColumn为建立关系的子表列,建立关系的两个列的 DataType 值必须相同。

建立好了关系,必须把这个关系加入到DataTable的ParentRelations属性或ChildRelations 属性,这两个属性包含这个表的所有的跟父

表的关系和跟子表的关系。若关系中此表是父表则将此关系加入到ChildRelations集合中,否则加入到ParentRelations集合中。

二、DataView

DataView表示用于排序、筛选、搜索、编辑和导航的 DataTable 的可绑定数据的自定义视图。可以将DataView同数据库的视图类比,

不过有点不同,数据库的视图可以跨表建立视图,DataView则只能对某一个DataTable建立视图。DataView一般通过

DataTable.DefaultView 属性来建立,再通过通过RowFilter 属性和RowStateFilter 属性建立这个DataTable的一个子集。

RowFilter属性用来筛选要查看DataTable中哪些行的表达式,这个表达式同上面所说的建立计算列的表达式相同。例如:"LastName = 'Smith'",这就是只查看列LastName的值为'Smith'的那些数据行。

RowStateFilter 属性用来设置 DataView 中的行状态筛选器,上面介绍DataRow时介绍了DataRow的状态,一个DataRow可能有五种状态,RowStateFilter就是可以通过这些状态来筛选要查看的行集。其实DataRow不仅有五种状态,DataRow还有版本的问题,比如当DataRow的状态为Modified,即这行已经被修改了,这时这个DataRow就会有两个版本,Current版本和Original版本(修改前的)。实际上RowStateFilter属性是综合了DataRow的状态和版本来筛选的(RowStateFilter确省值是CurrentRows)见下表:

成员名称说明

Added 一个新行。

CurrentRows 包括未更改行、新行和已修改行的当前行。

Deleted 已删除的行。

ModifiedCurrent 当前版本,原始数据(请参阅 ModifiedOriginal)的修改版本。

ModifiedOriginal 原始版本(尽管它后来已被修改并以 ModifiedCurrent 形式存在)。

None 无。

OriginalRows 包括未更改行和已删除行的原始行。

Unchanged 未更改的行。

DataView.Count属性得到的计数是在应用了 RowFilter 和 RowStateFilter 之后,获取 DataView 中记录的数量。

DataView是建立在DataTable基础上的,DataView.Table 属性可以得到此DataView对应的那个DataTable。DataView的行叫DataRowView,可以从DataRowView直接通过DataRowView.Row 属性得到此DataRowView对应的DataRow。

三、DataGrid

这里说的DataGrid是winform中的DataGrid,一般都是跟DataView绑定来显示DataTable中的数据,和修改DataTable中的数据。DotNet的DataGrid的功能强大,可是在使用上与以前的习惯不太一样,有时还比较麻烦,所以很多人都对这个DataGrid感到有些摸不着头脑,有一种无从下手的感觉,其实把一些概念搞清楚了许多问题就会迎刃而解了。

DataGrid通过DataSource 和 DataMember 属性来绑定其要显示的数据源。数据源一般是DataTable、DataView、DataSet等,不过将这些数据源绑定到DataGrid时实际上是绑定的DataView。若数据源是DataTable时,实际上是绑定了此DataTable的DefaultView,若数据源是DataSet时,则可以向 DataMember 属性设置一个字符串,该字符串指定要绑定到的表,然后再将DataMember指定的那个DataTable的DefaultView绑定到DataGrid。

所以DataGrid实际显示的是DataTable经过筛选的DataView。

◆ DataGrid以何种方式显示DataView的数据

DataGrid绑定到一个DataView后,由DataGrid.TableStyles中的DataGridTableStyle 对象的集合来控制这个DataView的哪些列要显示,列的宽度多少,列标头的文本是什么等等。确省的DataGrid.TableStyles中不包含任何对象,这时DataGrid将会按照DataView列的顺序将所有的列都显示出来。一般应用中都会设置TableStyles来控制显示的内容及格式。

例如DataGrid绑定到一张叫order的DataTable,这个DataTable包含了OrderID、CustomerID、OrderDate、ShipName、ShipAddress 等字段,如果不用TableStyles来控制显示的列和格式,将得到以下的显示结果:

figure-1

可以看到DataGrid将会按照DataView列的顺序将所有的列都显示出来

我们只想显示OrderID、CustomerID、OrderDate这三个字段,并且想将OrderID的列表头显示为“订单号”,CustomerID显示为“客户号”,OrderDate显示为“订单日期”,这就要用TableStyles来控制了。

新建一个TableStyle,将此TableStyle.MappingName属性对应到这个TableStyle要控制的那个DataTable的名字:

DataGridTableStyle myTableStyle = new DataGridTableStyle();

myTableStyle.MappingName = "myDateTable";

再建立三个DataGridColumnStyle,分别用来控制将要显示的三个列:

DataGridColumnStyle myColumnStyle1 = new DataGridTextBoxColumn();

myColumnStyle1.MappingName = "OrderID";

myColumnStyle1.HeaderText = "订单号";

DataGridColumnStyle myColumnStyle2 = new DataGridTextBoxColumn();

myColumnStyle2.MappingName = "CustomerID";

myColumnStyle2.HeaderText = "客户号";

DataGridColumnStyle myColumnStyle3 = new DataGridTextBoxColumn();

myColumnStyle3.MappingName = "OrderDate";

myColumnStyle3.HeaderText = "订单日期";

将这三个DataGridColumnStyle添加到TableStyle中:

myTableStyle.GridColumnStyles.Add(myColumnStyle1);

myTableStyle.GridColumnStyles.Add(myColumnStyle2);

myTableStyle.GridColumnStyles.Add(myColumnStyle3);

最后将TableStyle添加到DataGrid中:

dataGrid1.TableStyles.Add(myTableStyle);

将 TableStyle添加到DataGrid后,再绑定数据源,这时我们就会看到这样的数据显示了:

figure-2

◆ DataGrid的编辑修改

DataGrid支持对DataGrid所显示的DataTable的编辑修改,只要DataGrid的ReadOnly属性为False,就可以在DataGrid中直接修改

单元中的内容,修改完后数据将直接反应到此DataGrid对应的那个DataTable的单元。

如果这个DataTable是通过https://www.wendangku.net/doc/168622099.html,的可视化数据设计器新建DataAdapter,并生成了SelectCommand、InsertCommand、UpdateCommand、DeleteCommand这四个命令,用DataAdapter的Fill方法得来的,那么事情就简单了,修改过的DataTable你可以

直接用DataAdapter的UpDate方法写回到数据库。下面看一下https://www.wendangku.net/doc/168622099.html,的可视数据数据器生成的InsertCommand命令:

https://www.wendangku.net/doc/168622099.html,mandText = @"INSERT INTO Customers(CustomerID, CompanyName, ContactName, ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax) VALUES (@CustomerID, @CompanyName, @ContactName, @ContactTitle, @Address, @City, @Region, @PostalCode, @Country, @Phone, @Fax); SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax FROM Customers WHERE (CustomerID = @CustomerID)";

this.sqlInsertCommand1.Connection = this.sqlConnection2;

this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CustomerID", System.Data.SqlDbType.NVarChar, 5, "CustomerID"));

this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CompanyName",

System.Data.SqlDbType.NVarChar, 40, "CompanyName"));

this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ContactName", System.Data.SqlDbType.NVarChar,

30, "ContactName"));

this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ContactTitle", System.Data.SqlDbType.NVarChar, 30, "ContactTitle"));

this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Address", System.Data.SqlDbType.NVarChar, 60, "Address"));

this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@City", System.Data.SqlDbType.NVarChar, 15, "City"));

this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Region", System.Data.SqlDbType.NVarChar, 15, "Region"));

this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PostalCode", System.Data.SqlDbType.NVarChar, 10, "PostalCode"));

this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Country", System.Data.SqlDbType.NVarChar, 15, "Country"));

this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Phone", System.Data.SqlDbType.NVarChar, 24, "Phone"));

this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Fax", System.Data.SqlDbType.NVarChar, 24, "Fax"));

DataAdapter的SelectCommand是用来DataAdapter.Fill()方法来填充DataTable的,SelectCommand选择的数据表行集将被填充到DataTable中,然后DataGrid将它显示出来。

DataGrid在经过编辑修改后,其对应的DataTable中的行就可能出现文章上面所述的那五种状态,可能是新加的(Added),可能是修改

了的(Modified),可能是删除的(Deleted),DataAdapter.UpDate()方法将通过调用InsertCommand命令将状态为Added的行插入到数据库,UpdateCommand将状态为Modified的行在数据库中做修改,DeleteCommand将状态为Deleted的行在数据库真正的删除。

如果不是通过https://www.wendangku.net/doc/168622099.html,的可视化数据设计器新建DataAdapter,没有自动生成SelectCommand、InsertCommand、UpdateCommand、DeleteCommand这四个命令,那么就可能需要自己写InsertCommand、UpdateCommand、DeleteCommand命令,有一种情况就是当SelectCommand至少返回一个主键列或唯一的列时,可以通过SqlCommandBuilder来自动根据SelectCommand命令来自动生成另外三

个更新命令,例如:

SqlConnection myConn = new SqlConnection(myConnection);

SqlDataAdapter myDataAdapter = new SqlDataAdapter();

myDataAdapter.SelectCommand = new SqlCommand(mySelectQuery, myConn); //建立DataAdapter的SelectCommand命令

SqlCommandBuilder custCB = new SqlCommandBuilder(myDataAdapter);//建立此DataAdapter的CommandBuilder,

//这样系统就会给此DataAdapter自动生成InsertCommand、UpdateCommand、DeleteCommand三个命令。

否则,要用DataAdapter.UpDate()方法更新数据库就要自己写InsertCommand、UpdateCommand、DeleteCommand这三个命令,可以参考上面给出的https://www.wendangku.net/doc/168622099.html,自动生成的InsertCommand命令的写法。

◆数据绑定的同步

WinForm中很多控件都可以与数据源绑定,绑定又分两种情况:

简单数据绑定

简单数据绑定指将一个控件绑定到单个数据元素(如数据集表的列中的值)的能力。这是用于控件,如 TextBox 控件或 Label 控件(即通常只显示单个值的控件)的典型绑定类型。事实上,控件上的任何属性都可以绑定到数据库中的字段。

复杂数据绑定

复杂数据绑定指将一个控件绑定到多个数据元素的能力,通常绑定到数据库中的多条记录,或者绑定到多个任何其他类型的可绑定数据元素,一般是绑定到一个DataView。支持复杂绑定的控件的示例有DataGrid、ListBox 和 ErrorProvider 控件。

一般DataGrid控件都是跟一个DataView绑定,DataGrid的数据绑定属于复杂绑定,因为它绑定到有多条记录的表,DataGrid有两个属性同数据绑定有关:

DataGrid.DataSource 属性:获取或设置DataGrid所显示数据的数据源。一般是跟DataTable 、DataView 、DataSet 绑定,如果DataSource设定为DataSet,则引用包含的表不止一个,则必须向 DataMember 属性设置一个字符串,该字符串指定要绑定到的表。

DataGrid.DataMember 属性:获取或设置 DataSource中的特定列表,就是上述DataSource设定为DataSet时,要设定此属性来指定要绑定到的表。

经常有这种需求,一个窗体中有一个DataGrid,显示了一些数据,窗体上还有一些TextBox控件,用来显示DataGrid中的当前行的数据,一个TextBox控件对应DataGrid行的一个列,当DataGrid的当前行移动时,TextBox控件中的值也会跟着显示改变后的DataGrid的当前行。

要保证这些数据绑定控件保持同步就要一个统一管理数据绑定的机制来保证这些控件的同步,DotNet中负责数据同步的是BindingManagerBase,它是用来管理数据源的,绑定到同一个数据源的数据绑定控件都可以由BindingManagerBase统一管理。BindingManagerBase可以由Form.BindingContext.Item属性获得,此属性有两种重载:

public BindingManagerBase this[object DataSource] //获取与指定数据源关联的 BindingManagerBase

public BindingManagerBase this[object DataSource, string DataMember] //获取与指定数据源和数据成员相关联的一个 BindingManagerBase

所有的数据绑定控件的数据源同建立BindingManagerBase时传递的对象一样的,都将属于这个BindingManagerBase管理,比如,建立

一个如下的BindingManagerBase:

BindingManagerBase myBindingManagerBaseParent = this.BindingContext[myDataSet,"customers"];

如果Form上有个DataGrid的DataGrid.DataSource = myDataSet;DataGrid.DataMember = "customers",那么这个DataGrid的数据源

就在myBindingManagerBaseParent的管理之下了。

同样简单数据绑定的控件的DataSource也是跟 BindingManagerBase的DataSource一样,DataMember是BindingManagerBase的DataMember指定的那个表的某一列时,这个控件的数据源也在这个myBindingManagerBaseParent管理之下了:

dataGrid1.DataSource = myDataSet;

dataGrid1.DataMember = "customers";

textCustomerId.DataBindings.Add(new Binding("Text",myDataSet,"customers.customerid")); //TextBox的Text属性跟//myDataSet的customers表的customerid字段绑定

BindingManagerBase控制的数据源有个当前行的概念,控件一旦跟数据源绑定后,DataGrid将显示数据源表的所有数据,不过在DataGrid

的行标头里有个黑色的三角箭头用来指示当前行。简单绑定控件中显示的值将是数据源当前行的内容。

所以,只要我们改变BindingManagerBase的指针就行了,这个可以在界面上通过点击要到的那一行来改变当前行,也可以在程序中改变

当前行的设置:

myBindingManagerBaseParent.Position = 10;

BindingManagerBase.Position属性的变化就会引起BindingManagerBase当前行的变化,也就是跟这个数据源绑定的DataGrid的当前行

的变化,简单绑定控件的显示内容也就随之改变了,如下图。

figure-3

当前行是第一行,上面的三个TextBox控件也显示第一行的数据

figure-4

当前行是第四行,上面的三个TextBox控件也显示第四行的数据

BindingManagerBase的DataSource可以是DataSet,DataSet中可以有多个DataTable,这些DataTable可以通过DataRelaton(关系)

联系在一起,形成父表/子表的关系。比如,还是上面举过的例子,一个DataGrid显示Customer表,同时还想要有一个DataGrid来显示

当前Customer所有的order。这样我们就会需要两个BindingManagerBase了,一个BindingManagerBase对应Customer表,另一个BindingManagerBase对应order表,而且这个order表还要考虑到同Customer表的关系。

对应Customer的BindingManagerBase上面我们已经建立好了,下面我们来建立对应order的BindingManagerBase:

首先我们要建立Customer表和order表之间的关系myRelation:

DataColumn ParentColumn = myDataSet.Tables["customers"].Columns["customerid"]; //要建立关系的父表的列,相当于主键

DataColumn ChildColumn = myDataSet.Tables["orders"].Columns["customerid"]; //要建立关系的子表的列,相当于外键

DataRelation myRelation = new DataRelation("myRelation",ParentColumn,ChildColumn,false); //根据父表,子表的相关列建立关系

然后,通过关系,建立对应order表的BindingManagerBase:

myBindingManagerBaseChild = this.BindingContext[myDataSet,"customers.myRelation"]; //这个数据源将解析为一个父表中的客户对应的所有的

这样,当对应Customer的BindingManagerBase的当前行改变时,对应order的BindingManagerBase也将跟着变化,他们之间的关系

是由myRelation决定的,如下图:

figure-5

对应子表order的DataGrid显示对应父表中ALFKI 客户的所有order,当点击了“主表下移一行”按钮时,父表中的当前客户改变为ANATR时,

子表同样也改变为显示对应ANATR的所有order了

◆在程序中访问DataGrid中的内容

DataTable中有数据行DataRow,而在DataGrid中没有行这个对象,这让人感到很不习惯,也觉得不够自然。在DataTable中,一张表

的层次结构很清楚,DataTable.Rows属性可以得到这张表所包含的所有行的行集,通过行集的索引DataRowCollection[index]就可以得到

具体的一个DataRow,数据行的索引DataRow[index]又可以得到这一行的具体某一列的内容。

而DataGrid中就没有这么方便了,DataGrid只有两个属性可用,DataGrid.CurrentCell 属性,此属性返回一个DataGridCell类型的结构,DataGridCell结构指明此Cell所在的行号和列号。还有一个DataGrid.Item 属性,此属性有两个重载:

public object this[DataGridCell] //获取或设置指定的 DataGridCell 的值

public object this[int, int] //获取或设置位于指定行和列的单元格的值

可见,DataGrid中访问都是针对某个Cell进行的。经常的,我们需要从当前的Cell获得此Cell所对应的DataRow,比如界面中可能先选中DataGrid的某一行,或者某一个Cell,然后点击一个按钮,弹出一个新的窗口,窗口中显示这一行的所有单元的内容,并允许修改单元的值,最后保存关闭窗口。这就需要从当前的DataGrid所在的单元找到其所对应的DataTable所在的行和列。

而DataGrid中显示的数据可能经过DataView的DataView.RowFilter属性、DataView.RowStateFilter属性的过滤,还可能经过DataGrid 本身根据各个列的正向和反向排序,所以DataGrid的CurrentRowIndex属性所指示的行索引跟其对应的DataTable的行索引有很大的机会是不一样的,不能够根据DataGrid的CurrentRowIndex去获取其对应的DataTable的行。

这时BindingManagerBase又将发挥作用了,我们可以先建立一个对应此DataGrid绑定的数据源的BindingManagerBase,这样这个BindingManagerBase就可以管理这个数据源。

//设置DataGrid的数据源

dataGrid1.DataSource = myDataSet;

dataGrid1.DataMember = "customers";

//建立同DataGrid同样数据源的BindingManagerBase

BindingManagerBase myBindingManagerBaseParent = this.BindingContext[myDataSet,"customers"];

一旦建立了这个BindingManagerBase,就可以通过BindingManagerBase的当前行的属性来获取当前数据源的记录:

//BindingManagerBase的Current返回数据源的对象,对于绑定到DataView的数据源,需要将此对象显式

//的转换为 DataRowView类型

DataRowView myDataRowView =(DataRowView) myBindingManagerBaseParent.Current

这样,我们就可以从当前的Cell得到此Cell所在的DataRowView,DataRowView又可以通过DataRowView.Row属性及其方便的得到DataRow。

如果还要进一步,想要得到此Cell所对应的DataTable的具体单元,就是不光要得到DataRow,还要知道这个Cell所对应的列。

这又分两种情况:

一是DataGrid未使用TableStyles来设置DataGrid要显示的列和格式,数据源DataView的所有列都将按照DataView本身的顺序显示出来,这样可以直接取得对应的列索引:

//获取当前DataGrid单元的列索引,这个索引跟DataTable的索引是一样的

Int ColumnNumber = DataGrid.CurrentCell.ColumnNumber;

另一种情况是DataGrid使用了TableStyles来设置DataGrid要显示的列和格式,这样DataGrid单元的列索引跟DataTable的索引就可能是不一样的了,这就要用DataGrid的TableStyles了:

Int ColumnNumberDataGrid = DataGrid.CurrentCell.ColumnNumber; //获取当前DataGrid单元的列索引

Int ColumnNumberDataTable = DataGrid.TableStyles[0].GridColumnStyles[ColumnNumberDataGrid].MappingName

微软C#中DataGridView控件使用方法

DataGridView动态添加新行: DataGridView控件在实际应用中非常实用,特别需要表格显示数据时。可以静态绑定数据源,这样就自动为DataGridView控件添加相应的行。假如需要动态为DataGridView控件添加新行,方法有很多种,下面简单介绍如何为DataGridView控件动态添加新行的两种方法: 方法一: int index=this.dataGridView1.Rows.Add(); this.dataGridView1.Rows[index].Cells[0].Value = "1"; this.dataGridView1.Rows[index].Cells[1].Value = "2"; this.dataGridView1.Rows[index].Cells[2].Value = "监听"; 利用dataGridView1.Rows.Add()事件为DataGridView控件增加新的行,该函数返回添加新行的索引号,即新行的行号,然后可以通过该索引号操作该行的各个单元格,如dataGridView1.Rows[index].Cells[0].Value = "1"。这是很常用也是很简单的方法。 方法二: DataGridViewRow row = new DataGridViewRow(); DataGridViewTextBoxCell textboxcell = new DataGridViewTextBoxCell(); textboxcell.Value = "aaa"; row.Cells.Add(textboxcell); DataGridViewComboBoxCell comboxcell = new DataGridViewComboBoxCell(); row.Cells.Add(comboxcell); dataGridView1.Rows.Add(row);

DataTable按时间排序和查询

DataTable按时间排序和查询 因为从多表抽取数据,并且还要实现分页功能,所以只能先将数据形成DataTable,然后给GridView绑定,让GridView按照其中时间的字段进行倒序排列,并且还要能按时间区间段查询。 在网上找到排序方法如下: DataTable dt = new DataTable(); …… 一、重生法 dt.DefaultView.Sort = "字段名desc" 二、直接法 dv = new DataView(dt) dv.Sort = "字段名desc" 三、间接法 dv = New DataView(ds.Tables[0]) dv.Sort = "字段名desc" 我用的是第一种方法,但是发现时间的格式因为默认是一位数的时候不会在前面填0,例如,9月永远比10月大,后来用ToString实现了。 方法:DateTime.ToString("yyyy年MM月dd日(星期ddd)-HH:mm") 显示格式如:2008年09月22日(星期一)-11:31 查询代码: if (StartTime.Text != "" || EndTime.Text != "") { string searchString = ""; if (StartTime.Text != "") { searchString = "CreatTime > '" + StartTime.Text + "'"; } if (EndTime.Text != "") { if (searchString != "") { searchString += " and "; } searchString += "CreatTime < '" + EndTime.Text + " 23:59:59' ";

外研版英语非谓语动词的用法大全及答案解析推荐精选

外研版英语非谓语动词的用法大全及答案解析推荐精选 一、非谓语动词 1.The boss asked Tim to go and out if there was anyone else absent. A. find B. finding C. to find D. found 【答案】A 【解析】【分析】句意:如果有其他人缺席,老板让蒂姆去弄清楚。and前后并列,前面是动词不定式to go,此处要省略动词不定式to,故此处为动词原形find,故选A。 【点评】本题考查非谓语动词。当and链接动词不定式的时候后面一个不定式省去to。 2.—I think the environment is terrible these years. —Yes, it will be even worse the government takes action it. A. until; protect B. unless; to protect C. if; protecting 【答案】 B 【解析】【分析】句意:——我认为这几年来环境太糟糕了。——是的,环境会变得更糟糕,除非政府采取措施保护环境。A. until; 直到…为止,B. unless除非,如果不,连词;C. if 如果,连词;until和if放在这里,句意不通顺,take action to do sth. 采取行动去做某事,动词不定式作目的状语,故选B。 【点评】此题考查连词短语和固定搭配。 3.My mother doesn't allow me _______outside too late on school nights. A. to stay B. stay C. staying 【答案】 A 【解析】【分析】句意:在上学的日子里,我妈妈不允许我在外面待得太晚。Allow sb to do sth允许某人做某事,是固定用法,故答案选A。 【点评】考查动词不定式,掌握固定搭配。 4.—You can only keep the books for two weeks, Tom. Remember ____them on time. —I will. A. return B. returning C. to return 【答案】 C 【解析】【分析】句意:—这些书你能借两周,汤姆,记住按时归还它们。—我会的。remember to do记住去做某事; remember doing记得做过某事。根据You can only keep the books for two weeks, 可知借了之后要记得去还,记得去做某事要用to do,故选C。 【点评】考查remember的用法。牢记remember to do和remember doing的不同。 5.As a volunteer,the girl wants to visit sick kids in the hospital them up.() A. to cheer B. cheer C. cheering D. cheered 【答案】 A

PIC系列单片机的中断资源特点及其应用方法详解

PIC系列单片机的中断资源特点及其应用方法详解 1 PIC单片机简介PIC系列单片机是美国Microchip技术公司推出的高性能价格比的8位嵌入式控制器(Embedded Controller),它采用了精简指令集计算机RISC (Reduced Instruction Set Computer)和哈佛(Harvard)双总线以及两级指令流水线结构。具有高速度、低工作电压、低功耗等特点和优良的性能价格比,因而PIC系列单片机越来越受到单片机开发与应用工程技术人员的青睐。该系列独特的结构和中断资源使其在使用时与其它系列的单片机有许多不同之处。下面以PIC16CXX系列微控制器为例来介绍PIC 系列单片机的中断资源特点以及应用方法。 2 中断资源的开发与屏蔽图1是PIC16C64/64A/65/65A的中断逻辑电路图,其它型号芯睡的中断资源也大致相同,只是资源多少不一而已,但它们的中断入口只有一个(入口地址在004H)。PIC 单片机的中断大致可以分为两类。 第一类是由中断控制器INTCON直接控制的中断,包括外部引脚中断INT的RB口电平变化中断以及定时器TMRO溢出中断,它们的中断允许位和中断标志都在INTCON寄存器中。引脚中断INT和定时器TMRO溢出中断与其它微处理器相同。RB口电平变化中断是PIC 单片机特有的中断,当把RB口高4位I/O口线设置为输入时,只要这4位I/O 口线上的电平发生变化就会引起中断。RB口的电平中断特性对用户是非常有用的。用户可以直接利用这些口线的关键部位进行电平检测,并可利用中断进行保护性控制等操作;另一方面,电平中断特性还可以利用RB口的软件控制弱上拉特性组成一个矩阵键盘,并用按键唤醒CPU,这对于那些以电池供电的系统特别有用。 另一类是外围接口中断,包括定时器TMR1溢出中断、TMR溢出或匹配中断、同步串行口中断、异步串行口中断、并行从动口中断和CCP(Capture/Compare/PWM)中断等,而带A/D功能的PIC16C7X系列微处理器还有A/D转换完成中断。这些中断的允许位分别在PIE1和PIE2寄存器,而中断标志则分别在PIR1和PIR2中。 所有的中断都有自己的中断允许位和中断标志,外围接口中断不仅受各自的中断允许位控制,同时还共同受外围中断控制允许位的控制。全局中断允许位GID能够控制所有的中

DataGridView的用法

在C# WinForm下做过项目的朋友都知道,其中的DataGridView控件默认只支持DataGridViewButtonColumn、DataGridViewCheckBoxColumn、DataGridViewComboBoxColumn、DataGridViewImageColumn、DataGridViewLinkColumn和DataGridViewTextBoxColumn六种列类型,如果你想要在DataGridView的列中添加其它的子控件,则需要自己实现DataGridViewColumn和DataGridViewCell,这就意味着你需要从现有的列中继承并改写一些方法,如实现一个支持单选按钮的列,或支持三种选择状态的多选按钮的列。 上面两个截图分别为RadioButton列和支持三种状态的CheckBox列在DataGridView中的实现效果,我是在Windows 2003中实现的,因此显示的效果跟在XP和Vista下有些区别,Vista下CheckBox的第三种状态(不确定状态)显示出来的效果是一个实心的蓝色方块。 下面我看具体来看看如何实现这两种效果。 要实现自定义的DataGridView列,你需要继承并改写两个类,一个是基于DataGridViewColumn的,一个是基于DataGridViewCell的,因为

RadionButton和CheckBox的实现原理类似,因此我们可以将这两种列采用同一种方法实现。创建DataGridViewDisableCheckBoxCell和DataGridViewDisableCheckBoxColumn两个类,分别继承自DataGridViewCheckBoxCell和DataGridViewCheckBoxColumn。代码如下: public class DataGridViewDisableCheckBoxCell: DataGridViewCheckBoxCell { public bool Enabled { get; set; } // Override the Clone method so that the Enabled property is copied. public override object Clone() { DataGridViewDisableCheckBoxCell cell = (DataGridViewDisableCheckBoxCell)base.Clone(); cell.Enabled = this.Enabled; return cell; } // By default, enable the CheckBox cell. public DataGridViewDisableCheckBoxCell() { this.Enabled = true; } // Three state checkbox column cell protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { // The checkBox cell is disabled, so paint the border, background, and disabled checkBox for the cell. if (!this.Enabled) { // Draw the cell background, if specified. if ((paintParts & DataGridViewPaintParts.Background) == DataGridViewPaintParts.Background) { SolidBrush cellBackground = new SolidBrush(cellStyle.BackColor); graphics.FillRectangle(cellBackground,

DataSet与DataTable的区别

DataSet与DataTable的区别 DataSet:数据集。一般包含多个DataTable,用的时候,dataset["表名"]得到DataTable DataTable:数据表。 一: SqlDataAdapter da=new SqlDataAdapter(cmd); DataTable dt=new DataTable(); da.Fill(dt); ----------------- 直接把数据结果放到datatable中, 二: SqlDataAdapter da=new SqlDataAdapter(cmd); DataSet dt=new DataSet(); da.Fill(dt); ---------------- 数据结果放到dataset中,若要用那个datatable,可以这样:dataset[0] 更常见的用法: SqlDataAdapter da=new SqlDataAdapter(cmd); DataSet dt=new DataSet(); da.Fill(dt,"table1"); 用的时候:这样取datatable: dataset["table1"] 具体的应用: SqlConnection con = new SqlConnection("server=.;database=StuCourseDb1;uid=sa;pwd=xhz;"); SqlDataAdapter sda = new SqlDataAdapter("select * from student", con); DataSet ds = new DataSet(); sda.Fill(ds, "StuTable"); this.GridView1.DataSource = ds.Tables["StuTable"]; this.GridView1.DataBind(); ds.Dispose(); con.Close(); con.Dispose(); 还有很多;

c# datatable用法总结

在项目中经常用到DataTable,如果DataTable使用得当,不仅能使程序简洁实用,而且能够提高性能,达到事半功倍的效果,现对DataTable的使用技巧进行一下总结。 一、DataTable简介 (1)构造函数 DataTable() 不带参数初始化DataTable 类的新实例。 DataTable(string tableName) 用指定的表名初始化DataTable 类的新实例。 DataTable(string tableName, string tableNamespace) 用指定的表名和命名空间初始化DataTable 类的新实例。 (2) 常用属性 CaseSensitive 指示表中的字符串比较是否区分大小写。 ChildRelations 获取此DataTable 的子关系的集合。 Columns 获取属于该表的列的集合。 Constraints 获取由该表维护的约束的集合。 DataSet 获取此表所属的DataSet。DataSet相关信息,可见我以前的一篇文章《数据访问(2)-DataSet》 DefaultView 获取可能包括筛选视图或游标位置的表的自定义视图。 HasErrors 获取一个值,该值指示该表所属的DataSet 的任何表的任何行中是否有错误。 MinimumCapacity 获取或设置该表最初的起始大小。该表中行的最初起始大小。默认值为 50。 Rows 获取属于该表的行的集合。 TableName 获取或设置DataTable 的名称。 (3)常用方法 AcceptChanges() 提交自上次调用AcceptChanges() 以来对该表进行的所有更改。 BeginInit() 开始初始化在窗体上使用或由另一个组件使用的DataTable。初始化发生在运行时。 Clear() 清除所有数据的DataTable。 Clone() 克隆DataTable 的结构,包括所有DataTable 架构和约束。

人教版英语非谓语动词的用法大全含答案解析百度文库

人教版英语非谓语动词的用法大全含答案解析百度文库 一、非谓语动词 1.I really don't know this question. It is too hard. A. which to answer B. how to answer C. what to answer 【答案】 B 【解析】【分析】句意:我真的不知道如何回答这个问题。它太难了。which to answer回答哪一个; how to answer怎么回答;what to answer回答什么;据It's too hard.可知此处指的是这个问题太难,不知道如何回答,选B 2.My friend invited me ______ the Art Club , and I accepted it with pleasure. A. join B. to join C. joined D. joining 【答案】 B 【解析】【分析】句意:我的朋友邀请我参加艺术俱乐部,我愉快地接受了。A.动词原形;B.动词不定式;C. 动词过去式;D.动词的ing形式。invite sb. to do sth.邀请某人做某事。结合句意及结构,故选B。 3.As a volunteer,the girl wants to visit sick kids in the hospital them up.() A. to cheer B. cheer C. cheering D. cheered 【答案】 A 【解析】【分析】作为一名志愿者,这个女孩想去看望医院里生病的孩子使他们振作起来.根据句意可知这个女孩想去看望医院里生病的孩子的目的是使他们振作起来,故该空处填入动词不定式作目的状语,故填to cheer,故选A 4.As we all know, a person learns many things by making mistakes and ________ them. A. corrects B. correct C. to correct D. correcting 【答案】 D 【解析】【分析】句意:正如我们所知,一个人通过犯错误和纠正错误中,能学会很多东西。and,表并列的连词,前后动词用法应该一致,根据making,可知此处用动词ing形式,因此用correcting,故选D。 【点评】考查固定搭配。注意介词后接动词的ing形式。 5. You should ask Bob ________ his own clothes. He is ten years old now.

interrupt的用法和短语例句

interrupt的用法和短语例句 【篇一】interrupt的用法 interrupt的用法1:interrupt的基本意思是“打断(谈 话)”“打扰”,指因为某种外界因素而停下来,或为了某种目的而停下来,但不表明这种停止是否会继续下去。interrupt还可引申作“遮挡(视线或某物)”“使不连贯”解。 interrupt的用法2:interrupt可用作及物动词,也可用作不及物动词。用作及物动词时,接名词或代词作宾语。 【篇二】interrupt的常用短语 用作动词 (v.) interrupt in (v.+prep.) interrupt with (v.+prep.) 【篇三】interrupt的用法例句 1. Turkin tapped him on the shoulder. "Sorry to interrupt, Colonel." 图尔金拍拍他的肩膀。“不好意思打断您一下,上校。” 2. "If I may interrupt for a moment," Kenneth said. “能打搅一下吗,”肯尼思说。 3. Taller plants interrupt the views from the house. 稍高些的植物遮挡了房内的视线。 4. We interrupt our programmes for a newsflash. 我们中断节目,插播一条重要新闻。

5. Can I interrupt you just for a minute? 我能不能打断你们一下? 6. Can't you see I'm talking? Don't interrupt. 没看见我在说话吗?别插嘴。 7. Sorry to interrupt, but there's someone to see you. 对不起打扰一下,有人要见你。 8. It was all irrelevant, but I didn't dare interrupt him in midflow. 他说的事情全都不相关, 但我还是不敢中途打断他. 9. It is not polite to interrupt a speaker with frequent questions. 持续提问打断演讲者是不礼貌的. 10. It is not polite to interrupt when someone is talking. 在别人讲话时插嘴是不礼貌的. 11. You'd better not interrupt him. He is sleeping. 你别打扰他, 他在睡觉. 12. Don't interrupt; just hear me out. 别打岔, 听我说完. 13. Children must learn not to interrupt. 儿童应学会不要打断别人的讲话. 14. I don't interrupt him in his work. 我不想打扰他的工作.

DataGridView控件用法合集

DataGridView控件用法合集 目录 DataGridView控件用法合集(一) 1. DataGridView当前的单元格属性取得、变更 2. DataGridView编辑属性 3. DataGridView最下面一列新追加行非表示 4. DataGridView判断当前选中行是否为新追加的行 5. DataGridView删除行可否设定 6. DataGridView行列不表示和删除 DataGridView控件用法合集(二) 7. DataGridView行列宽度高度设置为不能编辑 8. DataGridView行高列幅自动调整 9. DataGridView指定行列冻结 10. DataGridView列顺序变更可否设定 11. DataGridView行复数选择 12. DataGridView选择的行、列、单元格取得 DataGridView控件用法合集(三) 13. DataGridView指定单元格是否表示 14. DataGridView表头部单元格取得 15. DataGridView表头部单元格文字列设定 16. DataGridView选择的部分拷贝至剪贴板 17.DataGridView粘贴 18. DataGridView单元格上ToolTip表示设定(鼠标移动到相应单元格上时,弹出说明信息) DataGridView控件用法合集(四) 19. DataGridView中的ContextMenuStrip属性 20. DataGridView指定滚动框位置 21. DataGridView手动追加列 22. DataGridView全体分界线样式设置 23. DataGridView根据单元格属性更改显示内容 24. DataGridView新追加行的行高样式设置る 25. DataGridView新追加行单元格默认值设置 DataGridView中输入错误数据的处理(五) 26. DataGridView单元格数据错误标签表示 27. DataGridView单元格内输入值正确性判断 28. DataGridView单元格输入错误值事件的捕获 DataGridView控件用法合集(六) 29. DataGridView行排序(点击列表头自动排序的设置) 30. DataGridView自动行排序(新追加值也会自动排序) 31. DataGridView自动行排序禁止情况下的排序 32. DataGridView指定列指定排序 DataGridView控件用法合集(七) 33. DataGridView单元格样式设置 34. DataGridView文字表示位置的设定 35. DataGridView单元格内文字列换行 36. DataGridView单元格DBNull值表示的设定 37. DataGridView单元格样式格式化 38. DataGridView指定单元格颜色设定

使用jquery dataTable

使用jquery dataTable jQuery 的插件dataT ables 是一个优秀的表格插件,提供了针对表格的排序、浏览器分页、服务器分页、筛选、格式化等功能。dataTables 的网站上也提供了大量的演示和详细的文档进行说明,为了方便学习使用,这里一步一步进行说明。 首先,需要到dataT ables 的网站https://www.wendangku.net/doc/168622099.html,/下载这个脚本库, 目前最新的版本是1.8.2,下载的压缩包中使用的jQuery 是1.4.4 。现在jQuery1.5.1 已经发布,所以,这里使用最新的jQuery 1.5.1 。 然后,在网页中先加入jQuery 的引用,然后,加入dataTables 的引用。 引入CSS文件和JS文件 -------------------------------------------------------------------------- -------------------------------------------------------------------------- -----------最简单的方式: $(document).ready(function() { $("#example").dataTable();

英语被动语态用法详解

英语被动语态用法详解 一、单项选择被动语态 1.As is estimated, more than 20 million shared bikes ______ into operation nationwide by 2025. A.will have been put B.will have put C.have been put D.will be putting 【答案】A 【解析】 【详解】 考查动词时态语态。句意:据估计,到2025年为止,全国将有2000多万辆共享单车投入运营。根据by 2025可知应用将来完成时,且主语与谓语动词构成被动关系,故应为将来完成时的被动语态。故选A。 2.(桂林部分学校高三质量检测)The wet weather will continue tomorrow,when a cold front________to arrive. A.will be expected B.is expecting C.expects D.is expected 【答案】D 【解析】 考查动词的时态和语态。句意为:预计将有一股冷锋到来,因此潮湿的天气明天将会继续。a cold front与expect之间是逻辑上的动宾关系,expect是发生在现在的动作,要用一般现在时,故选D项。 答案:D 3.—The manager has come back from his business trip. He is asking you for the report. — Oh,my god ! I haven’t finished it yet. But he ________ back at the company tomorrow. A.was expected B.will expect C.expected D.will be expected 【答案】A 【解析】 试题分析:考查时态和语态。句意:——经理出差回来了。他正在问你要报告。——哦,天哪,我还没完成呢。但是本来预计他明天回公司。根据语境,是过去预料他明天会回来,而且经理是被预计,故用一般过去时的被动。故选A。 【名师点睛】时态的考查要根据本句的句意,这句话一定要根据上下文判断动作发生的时间,要细心体会语境。还要注意时态语态。 考点:考查时态和语态 4.—Will Uncle Peterson come to my birthday party tomorrow? —Pity he ______ to Zimbabwe as a volunteer teacher. A.was sent B.has been sent C.had been sent D.would be sent

非谓语动词用法难点解析

非谓语动词用法难点解析 1.不定式和动名词作主语的区别 (1)动名词作主语通常表示抽象动作;而不定式作主语表示具体动作。 Smoking is prohibited(禁止)here.这里禁止抽烟。(抽象) It is not very good for you to smoke so much.你抽这么多烟对你身体很不好。(具体) (2)动名词作主语时,通常用以表示一件已知的事或经验。 不定式短语通常用来表示一件未完成的事或目的。 Climbing mountains is interesting.爬山很有趣。(经验) To finish the job in two days is impossible. (3)不定式做主语,一般用it当形式主语,把作主语的不定式短语后置。 It took me only five minutes to finish the job. (4)动名词作主语的句型 1)Doing...+ v. Reading is an art.阅读是门艺术。Seeing is believing.眼见为实。 2) It is + no use, no good (fun, a great pleasure, a waste of time, a bore...)等名词+doing sth. It is no use crying.哭没有用。It is no good objecting.反对也没有用。 It is a great fun playing football.打篮球很有趣。 It is a waste of time trying to explain.设法解释是浪费时间。 3)It is + useless (nice, good,interesting, expensive等形容词)+ doing sth. It is useless speaking.光说没用。 It is nice seeing you again.真高兴又遇到了你。 It is good Playing chess after supper.晚饭后弈棋挺好。 It is expensive running this car.开这种小车是浪费。 2.不定式、动名词和分词作表语的区别 (1)不定式作表语 1)不定式作表语一般表示具体动作,特别是表示将来的动作。 To do two things at a time is to do neither.--次做两件事等于未做。 What I would suggest is to start work at once.我的建议是立刻开始干。 2)如果主语是不定式(表示条件),表语也是不定式(表示结果)。 To see is to believe.百闻不如一见。 To work means to earn a living.工作就是为了生活。 3)如果主语是以aim,duty,hope,idea,happiness,job,plan,problem,purpose,thing,wish 等为中心的名词,或以what引导的名词性从句,不定式作表语是对主语起补充说明作用。 His wish is to buy a luxurious car in the near future.他的希望是在不远的将来买一辆豪华轿车。 The function of Louis Sullivan's architecture was to provide large uninterrupted floor areas and to allow ample light into the interior. The most important thing is to negotiate with them about the future of the plant. (2)动名词作表语:动名词作表语,表示抽象的一般性的行为。 Our work is serving the people.我们的工作是为人民服务。 His hobby is collecting stamps.他的爱好是集邮。 (3)分词作表语 分词做表语有两种情况,一种是现在分词做表语,一种是过去分词做表语,这两者区别是考试中经常考到的地方。一般来说,表示心理状态的动词如excite,interest等都是及物动词,汉语意思不是“激动”,“高

详解C__DataSet和DataTable

详解C# DataSet和DataTable 2010-03-12 10:53:44 作者:佚名来源:浏览次数:0 1、创建DataSet对象:DataSet ds = new DataSet("DataSetName"); 1、创建DataSet对象: DataSet ds = new DataSet("DataSetName"); 2、查看调用SqlDataAdapter.Fill创建的结构 da.Fill(ds,"Orders"); DataTable tbl = ds.Table[0]; foreach(DataColumn col in tbl.Columns) Console.WriteLine(col.ColumnName); 3、查看SqlDataAdapter返回的数据 ①、DataRow对象 DataTable tbl = ds.Table[0]; DataRow row = tbl.Row[0]; Console.WriteLine(ros["OrderID"]); ②、检查存储在DataRow中的数据 DataTable tbl = row.Table; foreach(DataColumn col in tbl.Columns) Console.WriteLine(row[col]); ③、检查DatTable中的DataRow对象 foreach(DataRow row in tbl.Rows) DisplayRow(row); 4、校验DataSet中的数据 ①、校验DataColumn的属性:ReadOnly,AllowDBNull,MaxLength,Unique ②、DataTable对象的Constrains集合:UiqueConstraints,Primarykey,ForeignkeyConstraints 通常不必刻意去创建ForeignkeyConstraints,因为当在DataSet的两个DataTable对象之间创建关系时会创建一个。 ③、用SqlDataAdapter.Fill模式来检索模式信息 5、编写代码创建DataTable对象 ①、创建DataTable对象:DataTable tbl = new DataTable("TableName"); ②、将DataTable添加到DataSet对象的Table集合 DataSet ds = new DataSet(); DataTable tbl = new DataTable("Customers"); ds.Tables.Add(tbl); DataSet ds = new DataSet(); DataTable tbl = ds.Tables.Add("Customers"); DataTable对象只能存在于至多一个DataSet对象中。如果希望将DataTable添加到多个DataSet中,就必须使用Copy方法或Clone方法。Copy方法创建一个与原DataTable结构相

史上最全的 构词法 用法详解

史上最全的构词法用法详解 语言中词的总和构成词汇,但是词汇并不是一堆杂乱无章、互不相关的群体,而是一个严密体系,在这个结构的体系中,词与词之间有着各种各样的联系。英语中的这些联系的规律总结起来就是构词。英语中构词的方法就是构词法。构词法主要有合成法、转化法、派生法和缩略法四种。掌握构词法是迅速扩大词汇量的重要方法之一。 第一节合成法 合成法就是指由两个或两个以上的单词合成的词叫合成词。这种构词方式主要有两种:复合法、结合法。合成法主要是构成合成名词和合成形容词。 复合法构成的复合词,它们各个结合的部分相互间的语法关系是紧密相关的。如blackboard和darkroom都是形容词和名词形成的结构,wr it ing desk是动词名词和名词形式的结构。 结合法形成的词是形态合成词,它的结合是用一个起来连接作用的中缀来把两个或两上以上的词根词素紧紧的连缀在一起。如,用辅音字母-s-来缀全两个词根词素构成的词有:salesman, towns people等。 合成的方式常见的有如下几种: 一、合成名词 1、名词/代词+名词: woman-doctor, women-doctors, workshop, spaceship, he-goat, coal fire, motorcycle, gas cooker, oil well, power plant, silk worm, gold mine, bottleneck, piano keys, teleph one receiver, television screen, chairman, fireman, motorman, police-officer, postman, pine tree, girl friend, boy friend, goldfish, raindrop, birdcage, breakfast time, flowerbed, tearoom, 2、动词+名词:blowpipe, flashlight, watchdog, call-girl, searchlight 3、形容词+名词: blacksmith, blackboard, supermarket, superman, darkroom, blackbird, highchair, hothouse, greenhouse, madman 4、动名词+名词: reading-room, sitting-room, classroom, schoolroom, dining room, building materials, dancing girl, cleaning women, flying machine, washing machine, working conditions, boilding point, drinking water, swimming pool, drinking cup, typing paper, writing desk, sewing machine, walking stick,

interrupt、using关键字的用法

C语言在8051单片机上的扩展(interrupt、using关键字的用法) 直接访问寄存器和端口 定义 sfr P0 0x80 sfr P1 0x81 sfr ADCON; 0xDE sbit EA 0x9F 操作 ADCON = 0x08 ; P1 = 0xFF ; io_status = P0 ; EA = 1 ; 在使用了interrupt 1 关键字之后,会自动生成中断向量 在ISR中不能与其他"后台循环代码"(the background loop code) 共享局部变量 因为连接器会复用在RAM中这些变量的位置,所以它们会有不同的意义,这取决于当前使用的不同的函数 复用变量对RAM有限的51来将很重要。所以,这些函数希望按照一定的顺序执行而不被中断。 timer0_int() interrupt 1 using 2 { unsigned char temp1 ; unsigned char temp2 ; executable C statements ; } "interrupt"声明表示向量生成在(8*n+3),这里,n就是interrupt参数后的那个数字 这里,在08H的代码区域生成LJMP timer0_int 这样一条指令 "using" tells the compiler to switch register banks on entry to an interrupt routine. This "context" switch is the fastest way of providing a fresh registerbank for an interrupt routine's local data and is to be preferred to stacking registers for very time-critical routines. Note that interrupts of the same priority can share a register bank, since there is no risk that they will interrupt each other. 'using' 告诉编译器在进入中断处理器去切换寄存器的bank。这个"contet"切换是 为中断处理程序的局部变量提供一个新鲜的寄存器bank 最快的方式。对时序要求严格的程序,是首选的stack寄存器(保存寄存器到stack)方式。

相关文档
相关文档 最新文档