我编写了一个类来运行存储过程,启动数据读取器并将内容放入数组列表中。
班级代码
public class GHPSlider
{
private clsDbAccess _db;
private clsDbAccess _tmpDb;
public ArrayList getBanners(int thisBannerType)
{
ArrayList HeroBanners = new ArrayList();
SqlDataReader _dr = null;
SqlCommand cmd = _db.Command;
if (_db.Connection.State == ConnectionState.Closed)
{
_db.Connection.Open();
}
cmd = _db.Command;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "GetGHPSlides";
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@ID", thisBannerType);
_dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
if (_dr.HasRows)
{
while (_dr.Read())
{
object[] values = new object[_dr.FieldCount];
_dr.GetValues(values);
HeroBanners.Add(values);
}
}
_dr.Close();
return HeroBanners;
}
}
在我的代码隐藏中,我试图访问 ArrayList 以便我可以遍历它并将代码输出到表示层。我对 n 层编程方式相当陌生,可以使用一些帮助来让我朝着正确的方向前进。
代码隐藏代码
Public Function GetHeros() As String
Dim thisTestSubject As ArrayList = New GHPSlider.getBanners(1)
'Loop through thisTestSubject ArrayList and place into HTML string to pass to literal or label
thisBannerSlideBuilderHTML = "<div style='z-index:0;background-color:#FFF;'><a href='" + thisBannerSlideURL.ToString() + "' onclick='RecordBannerClick(this, 'Hero', 'GHP', '" + thisBannerSlideTitle.ToString() + "');'><img alt='" + thisBannerSlideTitle.ToString() + "' src='" + thisBannerSlideImagePath.ToString() + "' /></a></div>";
'Place Inside Literal or Label to display to presentation layer
End Function
如果有人可以帮助我指出正确的方向,那就太好了!提前致谢。