troubleshooting Question

Pulling Data from DB with Class

Avatar of Scripter25
Scripter25 asked on
C#ASP.NET
7 Comments1 Solution261 ViewsLast Modified:
Treat me as a complete newb on this one
I am trying to get a row of values from the database so that I can I can display on my page and then use those same variables to insert into a temp table so far this is what I have even though I understand why it is not working I have no idea how to make it work.

here is my codebehind for the page that I am working with

        ODSClass gatci = new ODSClass();
        gatci.category_ID= Convert.ToInt32(Request.QueryString["categoryID"]);
        gatci.product_ID= Convert.ToInt32(Request.QueryString["productID"]);

        lbl_name.Text = gatci.orderItem_name;




in a class file I have this


public class ODSClass
{
      public ODSClass()
      {
            //
            // TODO: Add constructor logic here
            //
      }

    private string _SessionKey;  
    private decimal _LineTotal;
    private int _category_ID;
    private int _product_ID;  
    private string _orderItem_name;  
    private decimal _orderItem_price;  
    private int _orderItem_qty;  
    private string _orderItem_o1;  
    private string _orderItem_o2;  
    private string _orderItem_o3;  
    private string _orderItem_ac;  
    private string _orderItem_ph;
    private string _orderItem_photo;

    public string SessionKey
    {
        get { return _SessionKey; }
        set { _SessionKey = value; }
    }

    public decimal LineTotal
    {
        get { return _LineTotal; }
        set { _LineTotal = value; }
    }

    public int category_ID
    {
        get { return _category_ID; }
        set { _category_ID = value; }
    }

    public int product_ID
    {
        get { return _product_ID; }
        set { _product_ID = value; }
    }

    public string orderItem_name
    {
        get { return _orderItem_name; }
        set { _orderItem_name = value; }
    }

    public decimal orderItem_price
    {
        get { return _orderItem_price; }
        set { _orderItem_price = value; }
    }

    public int orderItem_qty
    {
        get { return _orderItem_qty; }
        set { _orderItem_qty = value; }
    }

    public string orderItem_o1
    {
        get { return _orderItem_o1; }
        set { _orderItem_o1 = value; }
    }

    public string orderItem_o2
    {
        get { return _orderItem_o2; }
        set { _orderItem_o2 = value; }
    }

    public string orderItem_o3
    {
        get { return _orderItem_o3; }
        set { _orderItem_o3 = value; }
    }
    public string orderItem_ac
    {
        get { return _orderItem_ac; }
        set { _orderItem_ac = value; }
    }

    public string orderItem_ph
    {
        get { return _orderItem_ph; }
        set { _orderItem_ph = value; }
    }

    public string orderItem_photo
    {
        get { return _orderItem_photo; }
        set { _orderItem_photo = value; }
    }



    public void GetAddToCartInfo(int category_ID, int product_ID)
    {
        SqlConnection sqlConnection1 = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\ASPNETDB.mdf;Integrated Security=True;User Instance=True");
        SqlCommand cmd = new SqlCommand();

        //category_ID = Convert.ToInt32(Request.QueryString["categoryID"]);
        //product_ID = Convert.ToInt32(Request.QueryString["productID"]);
       
        cmd.CommandText = "productAddToCartInfo";
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Connection = sqlConnection1;
        cmd.Parameters.AddWithValue("@category_ID", category_ID);
        cmd.Parameters.AddWithValue("@product_ID", product_ID);


        sqlConnection1.Open();

        SqlDataReader DReader = cmd.ExecuteReader();
        while (DReader.Read())
        {
            if (DReader.HasRows)
            {
                SessionKey = Convert.ToString(DReader.GetValue(0));
                LineTotal = Convert.ToDecimal(DReader.GetValue(1));
                product_ID = Convert.ToInt32(DReader.GetValue(2));
                orderItem_name = Convert.ToString(DReader.GetValue(3));
                orderItem_price = Convert.ToDecimal(DReader.GetValue(4));
                orderItem_qty = Convert.ToInt32(DReader.GetValue(5));
                orderItem_o1 = Convert.ToString(DReader.GetValue(6));
                orderItem_o2 = Convert.ToString(DReader.GetValue(7));
                orderItem_o3 = Convert.ToString(DReader.GetValue(8));
                orderItem_ac = Convert.ToString(DReader.GetValue(9));
                orderItem_ph = Convert.ToString(DReader.GetValue(10));
                orderItem_photo = Convert.ToString(DReader.GetValue(11));

            }
            else
            {
               // lbl_name.Text = "no rows";
            }
        }

    }
ASKER CERTIFIED SOLUTION
strickdd

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros