Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Pavel is correct about the result you are seeing being because it is a narrowing conversion. However, casting is NOT the answer.</p> <p>The Rows property is defined in the DataTable class, and is a DataRowCollection. However, there is a property defined in the strongly typed DataTable that handles returning the strongly typed rows.</p> <p>In VB.Net:</p> <pre><code>Public Default ReadOnly Property Item(ByVal index As Integer) As CustomerRow Get Return CType(Me.Rows(index), CustomerRow) End Get End Property </code></pre> <p>In C#:</p> <pre><code>public CustomerRow this[int index] { get { return ((CustomerRow)(this.Rows[index])); } } </code></pre> <p>As you can see, it is still casting the rows, but the point is that it is handled outside of your code so that you can focus on using your strongly typed dataset the way it was intended. So the way that you should use this, your code above would be rewritten to the following.</p> <p>In VB.Net:</p> <pre><code>lCustomerRow = lCustomerTable(0) </code></pre> <p>In C#:</p> <pre><code>lCustomerRow = lCustomerTable[0]; </code></pre> <p>Another important thing to note is that CustomerTable implements IEnumberable&lt;CustomerRow&gt;, which means that when you do a foreach loop (or anything with LINQ) you should use the table itself, rather than the Rows property, like so:</p> <pre><code>foreach (CustomerRow row in lCustomerTable) { DoSomethingWith(row); } </code></pre> <p>Hopefully this helps resolve anyone's confusion. I haven't used datasets much lately (typed or otherwise) since I started working with LINQtoSQL, which is WAY better at being able to handle data in a strongly typed manner. EntityFramework is probably the same, but I haven't gotten into it yet like I have with L2S. ;)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload