is need to use GetOrdinal
from the SqlDataReader
but my query is with joins and contains the same field name multiple times.
So I try
SELECT a.Id, b.Id FROM table1 AS a ...
but GetOrdinal seems dont understand the schema alias...
GetOrdinal('a.Id')`
throws an Exception... is there anyway to archive this?
GetOrdinal performs a case-sensitive lookup first. If it fails, a second, case-insensitive search occurs (a case-insensitive comparison is done using the database collation).
string ColumnValue; if (dr["ColumnName"] != null) ColumnValue = dr["ColumnName"].
ExecuteReader to retrieve rows from a data source. The DataReader provides an unbuffered stream of data that allows procedural logic to efficiently process results from a data source sequentially. The DataReader is a good choice when you're retrieving large amounts of data because the data is not cached in memory.
Give an alias name in your query
SELECT a.Id As EmployeeID, b.Id as ManagerId FROM table1 AS a ..
Now you can use the Alias names in your code to read the value
var employeeIdIndex = reader.GetOrdinal("EmployeeID")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With