15.02.2015 Views

C# 4 and .NET 4

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

848 ❘ ChaPTer 30 cOre AdO.net<br />

}<br />

this.columnProductName = new global::System.Data.DataColumn(<br />

"ProductName", typeof(string), null,<br />

global::System.Data.MappingType.Element);<br />

base.Columns.Add(this.columnProductName);<br />

this.columnSupplierID = new global::System.Data.DataColumn(<br />

"SupplierID", typeof(int), null,<br />

global::System.Data.MappingType.Element);<br />

base.Columns.Add(this.columnSupplierID);<br />

this.columnCategoryID = new global::System.Data.DataColumn("CategoryID",<br />

typeof(int), null, global::System.Data.MappingType.Element);<br />

base.Columns.Add(this.columnCategoryID);<br />

this.columnQuantityPerUnit = new<br />

global::System.Data.DataColumn("QuantityPerUnit", typeof(string), null,<br />

global::System.Data.MappingType.Element);<br />

base.Columns.Add(this.columnQuantityPerUnit);<br />

this.columnUnitPrice = new global::System.Data.DataColumn("UnitPrice",<br />

typeof(decimal), null, global::System.Data.MappingType.Element);<br />

base.Columns.Add(this.columnUnitPrice);<br />

this.columnUnitsInStock = new global::System.Data.DataColumn("UnitsInStock",<br />

typeof(short), null, global::System.Data.MappingType.Element);<br />

base.Columns.Add(this.columnUnitsInStock);<br />

this.columnUnitsOnOrder = new global::System.Data.DataColumn("UnitsOnOrder",<br />

typeof(short), null, global::System.Data.MappingType.Element);<br />

base.Columns.Add(this.columnUnitsOnOrder);<br />

this.columnReorderLevel = new global::System.Data.DataColumn("ReorderLevel",<br />

typeof(short), null, global::System.Data.MappingType.Element);<br />

base.Columns.Add(this.columnReorderLevel);<br />

this.columnDiscontinued = new global::System.Data.DataColumn("Discontinued",<br />

typeof(bool), null, global::System.Data.MappingType.Element);<br />

base.Columns.Add(this.columnDiscontinued);<br />

this.columnProductID.AutoIncrement = true;<br />

this.columnProductID.AllowDBNull = false;<br />

this.columnProductID.ReadOnly = true;<br />

this.columnProductName.AllowDBNull = false;<br />

this.columnDiscontinued.AllowDBNull = false;<br />

[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]<br />

[global::System.CodeDom.Compiler.GeneratedCodeAttribute(<br />

"System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]<br />

public ProductRow NewProductRow() {<br />

return ((ProductRow)(this.NewRow()));<br />

}<br />

code download product.cs<br />

NewRowFromBuilder() is called internally from the DataTable class’s NewRow() method. Here, it creates a<br />

new strongly typed row. The DataRowBuilder instance is created by the DataTable class, <strong>and</strong> its members<br />

are accessible only within the System.Data assembly:<br />

[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]<br />

[global::System.CodeDom.Compiler.GeneratedCodeAttribute(<br />

"System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]<br />

protected override global::System.Data.DataRow NewRowFromBuilder(<br />

global::System.Data.DataRowBuilder builder) {<br />

return new ProductRow(builder);<br />

}<br />

The last class to discuss is the ProductRow class, derived from DataRow. This class is used to provide typesafe<br />

access to all fields in the data table. It wraps the storage for a particular row, <strong>and</strong> provides members to<br />

read (<strong>and</strong> write) each of the fields in the table.<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!