asp.net c#app_data

has the attached codes working fine, but I do not know how to call on aspx page.
It suppose has while statement to call and loop every rows.

using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
 
/// <summary>
/// Summary description for decisiontable
/// </summary>
public class decisiontable
{
   int _bondlistid;
   int _countpublicRd;
   int _ficoscore;
   int _statecode;
   int _manualbondamt;
    public int bondamt
    {
        get { return _manualbondamt; }
        set { _manualbondamt = value; }
    }
    public int bondlistid
    {
        get { return _bondlistid; }
        set { _bondlistid = value; }
    }
    public int countpublicRd
    {
        get { return _countpublicRd; }
        set { _countpublicRd = value; }
    }
    public int ficoscore
    {
        get { return _ficoscore; }
        set { _ficoscore = value; }
    }
    public int statecode
    {
        get { return _statecode; }
        set { _statecode = value; }
    }
    
    public  SqlDataReader viewyearterms
    {
        get {
           
            SqlConnection pagedbconnection = new SqlConnection();
            try
            {
                string dbconnectionstring = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
                string commandtext = "decisiontable";
 
                pagedbconnection.ConnectionString = dbconnectionstring;
 
                SqlCommand pagecommand = new SqlCommand(commandtext, pagedbconnection);
                pagecommand.CommandType = CommandType.StoredProcedure;
                //add parameter
                SqlParameter bondlistid_param = new SqlParameter();
                bondlistid_param.ParameterName = "@bondlistid";
                bondlistid_param.SqlDbType = SqlDbType.Int;
                bondlistid_param.Direction = ParameterDirection.Input;
                bondlistid_param.Value = _bondlistid;
                pagecommand.Parameters.Add(bondlistid_param);
 
                SqlParameter bondamt_param = new SqlParameter();
                bondamt_param.ParameterName = "@manualbondamt";
                bondamt_param.SqlDbType = SqlDbType.Money;
                bondamt_param.Direction = ParameterDirection.Input;
                bondamt_param.Value = _manualbondamt;
                pagecommand.Parameters.Add(bondamt_param);
                pagedbconnection.Open();
                SqlDataReader test = pagecommand.ExecuteReader();
                return test;
 
 
            }   
 
            catch (Exception ex)
            {
                //If the exception occurs, handle it
                throw (ex);
            }
            
            finally
            {
                //myconnection.close();
                pagedbconnection.Close();
            }
 
        }
    }
 
}

Open in new window

riskyricky1972Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ted BouskillSenior Software DeveloperCommented:
If you want to learn how to display data in web pages work through the tutorials at www.asp.net  It's an excellent site.

NOTE: I did some best practice changes to your code below.  If you use the 'using' keyword it automatically disposes an object even if there is an exception.

Also you add overhead to catch an exception then are rethrowing it.  That is a waste of effort.
    public  SqlDataReader viewyearterms
    {
        get
        {          
            SqlDataReader drResult; 
           
            try
            {
                string dbconnectionstring = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
 
                // The following method is a best practice (search the web for more information)
                using (SqlConnection pagedbconnection = new SqlConnection())
                {
 
                    string commandtext = "decisiontable";
 
                    pagedbconnection.ConnectionString = dbconnectionstring;
 
                    using (SqlCommand pagecommand = new SqlCommand(commandtext, pagedbconnection))
                    {
 
                        pagecommand.CommandType = CommandType.StoredProcedure;
                        //add parameter
                        SqlParameter bondlistid_param = new SqlParameter();
                        bondlistid_param.ParameterName = "@bondlistid";
                        bondlistid_param.SqlDbType = SqlDbType.Int;
                        bondlistid_param.Direction = ParameterDirection.Input;
                        bondlistid_param.Value = _bondlistid;
                        pagecommand.Parameters.Add(bondlistid_param);
 
                        SqlParameter bondamt_param = new SqlParameter();
                        bondamt_param.ParameterName = "@manualbondamt";
                        bondamt_param.SqlDbType = SqlDbType.Money;
                        bondamt_param.Direction = ParameterDirection.Input;
                        bondamt_param.Value = _manualbondamt;
                        pagecommand.Parameters.Add(bondamt_param);
                        pagedbconnection.Open();
         
                       drResult = pagecommand.ExecuteReader();
                    } 
                }
            }   
            catch (Exception ex)
            {
                // Why catch it if you rethrow it?
                throw (ex);
            }
 
            return drResult;
        }
    }

Open in new window

0
riskyricky1972Author Commented:
How to call on aspx page?
0
Ted BouskillSenior Software DeveloperCommented:
Go to www.asp.net and work through the databinding examples.  They are far better than what I could type here.
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

riskyricky1972Author Commented:
why don't you show me?
0
Ted BouskillSenior Software DeveloperCommented:
The following page shows runnable samples AND source code.
http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/data/gridview.aspx

Why won't you review those samples?  I love to share my expertise and show people how to solve problems themselves, however, I manage a team of web developers.  I don't have time to duplicate examples that are of excellent quality on that site.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
riskyricky1972Author Commented:
Lead Web Developers: If you do not have time, do not help here. The link you provided does not help to solve my issue. all of my codes are in code behind in app_data with stored procedures. the one you shown me use all different approaches.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.