我不断收到读者错误。我只想能够从阅读器返回单个值。谁能帮帮我吗?
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;