I have a very simple mapping function called "BuildEntity" that does the usual boring left / right encoding needed to dump my reader data into my domain object. (shown below) My question is this: if I do not return each column in this mapping as it is, I get a "System.IndexOutOfRangeException" exception and would like to know if ado.net has something to fix this, t need to return every column with every call in SQL ...
What I'm really looking for is something like "IsValidColumn", so I can save this 1 mapping function in my DataAccess class with all the defined left / right mappings and work even if sproc does not return each in the column ...
Using reader As SqlDataReader = cmd.ExecuteReader()
Dim product As Product
While reader.Read()
product = New Product()
product.ID = Convert.ToInt32(reader("ProductID"))
product.SupplierID = Convert.ToInt32(reader("SupplierID"))
product.CategoryID = Convert.ToInt32(reader("CategoryID"))
product.ProductName = Convert.ToString(reader("ProductName"))
product.QuantityPerUnit = Convert.ToString(reader("QuantityPerUnit"))
product.UnitPrice = Convert.ToDouble(reader("UnitPrice"))
product.UnitsInStock = Convert.ToInt32(reader("UnitsInStock"))
product.UnitsOnOrder = Convert.ToInt32(reader("UnitsOnOrder"))
product.ReorderLevel = Convert.ToInt32(reader("ReorderLevel"))
productList.Add(product)
End While
James bauer
source
share