Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Now here is my plan.

 

If I have made an succesful query returning me a dataset, or whatever we call (cross nationality).

 

I want to pack each of a table row data in an object representing the logical definition of the data table.

 

For example a query collecting data from a 'person' table with all person attributes as FirstName, LastName, Address, Sex, Email etc.

 

I want to pack each of the person in an Person object, which I want to 'store' in an array which I want to return as the last thing.

 

Now in my presentation layer I want to 'unpack' this array and present the data. Does anyone have a example of that.

 

I have tried coding a cart example which does not work. I am missing something, which I hope someobne in here can help me with.

 

#My code with a shopping cart example.#

 

using System;

using System.Collections;

using MySql;

using MySql.Data;

using MySql.Data.MySqlClient;

 

public class CartData

{

private int _ProductId;

private int _PhotoId;

private int _CatPhotoId;

private int _SupplierId;

private string _CartGuId;

private string _ProductName;

private string _ProductDescription;

private decimal _ProductPrice;

private int _Amount;

 

//Properties

 

public CartData()

{

}

 

public int ProductId

{

get { return _ProductId;}

set { _ProductId = value;}

}

public int PhotoId

{

get { return _PhotoId;}

set { _PhotoId = value;}

}

public int CatPhotoId

{

get { return _CatPhotoId;}

set { _CatPhotoId = value;}

}

public int SupplierId

{

get { return _SupplierId;}

set { _SupplierId = value;}

}

public string CartGuId

{

get { return _CartGuId;}

set { _CartGuId = value;}

}

public string ProductName

{

get { return _ProductName;}

set { _ProductName = value;}

}

public string ProductDescription

{

get { return _ProductDescription;}

set { _ProductDescription = value;}

}

public decimal ProductPrice

{

get { return _ProductPrice;}

set { _ProductPrice = value;}

}

public int Amount

{

get { return _Amount;}

set { _Amount = value;}

}

 

}

 

/// <summary>

/// Summary description for CartContent.

/// </summary>

public class CartContent

{

string guid;

 

public CartContent()///Constructor

{

//Læs guid fra cookie hos klienten.

Customer MyCustomer = new Customer();

this.guid = MyCustomer.GetCookie("CustomerGuId");

}

 

//Hent indkøbskurv

public ArrayList GetCart()

{

string strSql = "SELECT DISTINCT product.id AS product_id, product_category.photo_id AS prod_cat_photo_id, product.supplier_id, product.photo_id AS prod_photo_id, shopping_cart.guid, shopping_cart.amount, product.name AS product_name, product.price as product_price, product.description AS product_description FROM product INNER JOIN product_category ON (product.id = product_category.product_id) INNER JOIN shopping_cart ON (product_category.product_id = shopping_cart.product_id) WHERE guid = '"+ guid +"'ORDER BY product_name;";

DbConnector dbCon = new DbConnector();

MySqlDataReader rdr = dbCon.DbConnect(strSql);

dbCon.DbClose();

 

ArrayList arrCart = new ArrayList();

 

while (rdr.Read())

{

CartData c = new CartData();

 

c.ProductId = Convert.ToInt32(rdr["product_id"]);

c.CatPhotoId = Convert.ToInt32(rdr["prod_cat_photo_id"]);

c.SupplierId = Convert.ToInt32(rdr["supplier_id"]);

c.PhotoId = Convert.ToInt32(rdr["photo_id"]);

c.CartGuId = rdr["guid"].ToString();

c.Amount = Convert.ToInt32(rdr["amount"]);

c.ProductName = rdr["product_name"].ToString();

c.ProductPrice = Convert.ToDecimal(rdr["product_price"]);

c.ProductDescription = rdr["product_description"].ToString();

arrCart.Add©;

}

return arrCart;

}

 

}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...