Returning a single row

前端 未结 10 2319
野的像风
野的像风 2021-02-13 06:58

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:18

    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.

提交回复
热议问题