データベースから単一の行を返そうとしています:
using (connection = new SqlConnection(ConfigurationManager.AppSettings["connection"]))
{
using (command = new SqlCommand(@"select top 1 col_1, col_2 from table1", connection))
{
connection.Open();
using (reader = command.ExecuteReader())
{
reader.Read();
return reader["col_1"];
}
}
}
しかし、次のエラー メッセージが表示されます。
コンパイラ エラー メッセージ: CS0266: 型 'object' を 'string' に暗黙的に変換できません。明示的な変換が存在します (キャストがありませんか?)
90 行目: return reader["col_1"];
私は本当に明らかな間違いを犯していると確信していますが、単一の行の例を見つけることができないようです。私が見つけたすべての例は、while loop
.