Returning a single row

前端 未结 10 2323
野的像风
野的像风 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:33

    reader["col_1"] returns an object. I assume your function has a return type of string, which is where the error is coming from, it cannot implicitly convert the object to a string.

    You probably expect a string returned from col_1 so you can just cast it: (string)reader["col_1"].

提交回复
热议问题