Hi all:
I creating a data range control to be used on several pages in my site. It gives me an out of memory error when entering the do/while loop but I can't figure out why. Does anything jump out at you guys?
Code:private void Page_Load(object sender, System.EventArgs e) { SqlConnection cnn = new SqlConnection(ConfigurationManager.AppSettings["CnnString"]); SqlCommand myCommand; SqlDataReader myReader; ArrayList dateTimeList; DateTime dtBegin; DateTime dtEnd; if (!IsPostBack) { dtBegin = Convert.ToDateTime(string.Format("{0:MM/dd/yyyy}", "10/1/2005")); cnn.Open(); myCommand = new SqlCommand(); myCommand.Connection = cnn; myCommand.CommandType = CommandType.StoredProcedure; myCommand.CommandText = "usp_GetDate"; dateTimeList = new ArrayList(); myReader = myCommand.ExecuteReader(); if (myReader.HasRows) { myReader.Read(); dtEnd = Convert.ToDateTime(myReader[0]); } do { dateTimeList.Add(string.Format("{0:MM/dd/yyyy}", dtBegin)); dtBegin = DateAdd(DateInterval.Day, 1, dtBegin); } while (!(dtEnd < dtBegin)); dateTimeList.Reverse(); ddlBeginDate.DataSource = dateTimeList; ddlBeginDate.DataBind(); ddlEndDate.DataSource = dateTimeList; ddlEndDate.DataBind(); } myReader.Close(); myCommand.Dispose(); cnn.Close(); cnn.Dispose(); } }


Reply With Quote



Bookmarks