public List <TDRate> SelectCurrent() { string DBConnect = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString; SqlConnection myConn = new SqlConnection(DBConnect); String sqlstmt = "SELECT tdTerm, tdRate From TDRate " + "where GETDATE() between tdEffFrom and tdEffTo"; SqlDataAdapter da = new SqlDataAdapter(sqlstmt, myConn); DataSet ds = new DataSet(); da.Fill(ds); List <TDRate> rteList = new List <TDRate>(); int rec_cnt = ds.Tables[0].Rows.Count; if (rec_cnt == 0) { rteList = null; } else { foreach (DataRow row in ds.Tables[0].Rows) { int term = Convert.ToInt32(row["tdTerm"]); float rate = Convert.ToSingle(row["tdRate"]); TDRate objRate = new TDRate(term, rate); rteList.Add(objRate); } } return(rteList); }
public static List <TDRate> SelectCurrent() { List <TDRate> rateList = new List <TDRate>(); string connectionString = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString; SqlConnection connection = new SqlConnection(connectionString); try { connection.Open(); string sqlStmt = "Select * from TDRate where GETDATE() between EffFrom and EffTo order by Term"; SqlCommand cmd = new SqlCommand(sqlStmt, connection); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { TDRate rate = Read(dr); rateList.Add(rate); } } finally { connection.Close(); } return(rateList); }
protected void Page_Load(object sender, EventArgs e) { string custId = string.Empty; if (!Page.IsPostBack) { // Assign session variables for customer Id and Name if (Session["SScustId"] != null) { LblCustId.Text = Session["SScustId"].ToString(); LblCustname.Text = Session["SScustName"].ToString(); } // Instantiate the TDRate class to invoke the GetCurrentRate() method. // Instantiate a list to store the TDRate records. TDRate tdRate = new TDRate(); List <TDRate> rateList = tdRate.GetCurrentRate(); DdlTerm.Items.Clear(); DdlTerm.Items.Insert(0, new ListItem("--Select--", "0")); //AppendDataBoundItems property allows you to add items to the ListControl object before data binding occurs. DdlTerm.AppendDataBoundItems = true; // set Term as the dropdown list text and intRate as the dropdown list values // set the rateList as the DataSource and invoked the DataBind() method. DdlTerm.DataTextField = "Term"; DdlTerm.DataValueField = "IntRate"; DdlTerm.DataSource = rateList; DdlTerm.DataBind(); } }
public static TDRate Read(SqlDataReader dr) { TDRate rate = new TDRate(); rate.Term = Convert.ToInt32(dr["Term"].ToString()); rate.Rate = Convert.ToDouble(dr["Rate"].ToString()); return(rate); }