I\'m trying to return a single row from a database:
using (connection = new SqlConnection(ConfigurationManager.AppSettings[\"connection\"]))
{
using (command
reader["col_1"]
returns object
.
You want something like reader.GetString(reader.GetOrdinal("col_1"))
.
Edit -> I just wanted to add a note here that, in addition to the concerns others have raised, a SELECT TOP
without an ORDER BY
can give you random results based on schema changes and/or merry-go-round scans.