Returning a single row

前端 未结 10 1472
轻奢々
轻奢々 2021-02-13 06:55

I\'m trying to return a single row from a database:

using (connection = new SqlConnection(ConfigurationManager.AppSettings[\"connection\"]))
{
    using (command         


        
10条回答
  •  南旧
    南旧 (楼主)
    2021-02-13 07:28

    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.

提交回复
热议问题