Returning a single row

前端 未结 10 1473
轻奢々
轻奢々 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:35

    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"].

提交回复
热议问题