我不斷收到讀者的錯誤。我只想要能夠從閱讀器中返回單個值。誰能幫幫我嗎?不能將類型'System.Data.Common.DbDataReader'隱式轉換爲'字符串'
DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.SqlClient");
DbConnection conn = factory.CreateConnection();
conn.ConnectionString = ConfigurationManager.ConnectionStrings["CompanyConnection"].ConnectionString;
DbCommand comm = conn.CreateCommand();
comm.CommandText = "getStockPrice";
comm.CommandType = CommandType.StoredProcedure;
DbParameter param = comm.CreateParameter();
param.ParameterName = "@company";
param.Value = CompanyName;
param.DbType = DbType.String;
comm.Parameters.Add(param);
conn.Open();
DbDataReader reader = comm.ExecuteReader();
string stock = reader;
reader.Close();
conn.Close();
return Convert.ToDouble(stock);
這是存儲過程:
@company varchar(50)
AS
Select stockPrice From Company_t
where companyName = @company;