Click here to Skip to main content
15,887,027 members
Home / Discussions / C#
   

C#

 
QuestionParallel Array Assignment Pin
Member 128361456-Nov-16 19:37
Member 128361456-Nov-16 19:37 
AnswerRe: Parallel Array Assignment Pin
Richard MacCutchan6-Nov-16 21:42
mveRichard MacCutchan6-Nov-16 21:42 
AnswerRe: Parallel Array Assignment Pin
OriginalGriff6-Nov-16 23:26
mveOriginalGriff6-Nov-16 23:26 
GeneralRe: Parallel Array Assignment Pin
Richard MacCutchan7-Nov-16 0:20
mveRichard MacCutchan7-Nov-16 0:20 
GeneralRe: Parallel Array Assignment Pin
OriginalGriff7-Nov-16 0:51
mveOriginalGriff7-Nov-16 0:51 
Questionadding the values in columns in datagridview Pin
Member 128343325-Nov-16 7:27
Member 128343325-Nov-16 7:27 
QuestionRe: adding the values in columns in datagridview Pin
Richard MacCutchan5-Nov-16 21:02
mveRichard MacCutchan5-Nov-16 21:02 
QuestionList inside a List using with a repeater Pin
Member 128324604-Nov-16 1:09
Member 128324604-Nov-16 1:09 
Hi guys,

I've been struggling with a list inside a list. I have a table "cart_product" that contains 2 columns: cart_id and product_id.
Also I have a product table "product" with al the information of a product ( name, product_id, price etc ). I want to get the product information when I read the cart from the website, so I can show the price, name etc.

The problem I have is that I can't combine the 2 classes that I've made. If I use them separate its works correctly but combining them wont work..

C#
public void Fetch()
{
    database.Query("SELECT * FROM ws_cart_product WHERE cart_id=?cart_id;");
    database.Add("?cart_id", cart_id);

    foreach (DataRow row in database.FetchAsDataTable().Rows)
    {
        cart_id = global.ParseInt(row["cart_id"].ToString());
        if (row["product_id"] != DBNull.Value)
        {
            product_id = global.ParseInt(row["product_id"].ToString());
        }
        if (row["parent_id"] != DBNull.Value)
        {
            parent_id = global.ParseInt(row["parent_id"].ToString());
        }
        if (row["quantity"] != DBNull.Value)
        {
            quantity = global.ParseInt(row["quantity"].ToString());
        }

// Here I try to combine them
        Product product = new Product();
        product.product_id = global.ParseInt(row["product_id"].ToString());
        product.Fetch();
    }
}


C#
public void Fetch()
{
    StringBuilder query = new StringBuilder();
    query.Append("SELECT *,  ");
    query.Append("(");
    query.Append("SELECT thumbnail ");
    query.Append("FROM ws_product_file, file ");
    query.Append("WHERE file.file_id=ws_product_file.file_id ");
    query.Append("AND ws_product_file.product_id=ws_product.product_id ");
    query.Append("AND file.status_id=1 ");
    query.Append("ORDER BY sortorder DESC LIMIT 0,1");
    query.Append(") ");
    query.Append("AS thumbnail,  ");
    query.Append("(");
    query.Append("SELECT mimetype ");
    query.Append("FROM ws_product_file, file ");
    query.Append("WHERE file.file_id=ws_product_file.file_id ");
    query.Append("AND ws_product_file.product_id=ws_product.product_id ");
    query.Append("AND file.status_id=1 ");
    query.Append("ORDER BY sortorder DESC LIMIT 0,1");
    query.Append(") ");
    query.Append("AS mimetype ");
    query.Append("FROM webpage, ws_product ");
    query.Append("WHERE webpage.status_id=1  ");
    query.Append("AND webpage.webpage_type_id=4 ");
    query.Append("AND ws_product.product_id=webpage.webpage_type_content_id ");
    query.Append("AND ws_product.product_id=?product_id; ");
    database.Query(query.ToString());
    database.Add("?product_id", product_id);

    foreach (DataRow row in database.FetchAsDataTable().Rows)
    {
        product_id = global.ParseInt(row["product_id"].ToString());
        if (row["parent_id"] != DBNull.Value)
        {
            parent_id = global.ParseInt(row["parent_id"].ToString());
        }
        if (row["status_id"] != DBNull.Value)
        {
            status_id = global.ParseInt(row["status_id"].ToString());
        }
        if (row["create_date"] != DBNull.Value)
        {
            create_date = global.ParseDateTime(row["create_date"].ToString());
        }
        if (row["product_no"] != DBNull.Value)
        {
} 
// There is more...
}
}


If I run them seperate the result would become:

JavaScript
{Dotcontent.CartProduct}

  cart_id: 1
  product_id: 64
  parent_id: 0
  quantity: 2
  customer_id: 0
  guid: null


{Dotcontent.Product}

  webpage_id: 145
  website_id: 0
  status_id: 1
  url: "mode360-composer-fotostudio-fa40"
  type: null
  webpage_type_id: 0
  webpage_type_content_id: 0
  version: 0
  language_id: 0
  parent_id: 0
  related_webpage_id: 0
  title: "Mode360 Composer Fotostudio FA40"
  text: null
  short_description: null
  meta_description: null
  published_from: 1-1-0001
  published_to: 1-1-0001
  created_on: 1-1-0001
  created_by: 0
  product_id: 64
  create_date: 16-9-2016
  product_no: "291610"
  ean: ""
  price_on_request: False
  weight: 0
  brand_id: 0
  in_export: False
  template_id: 1
  mimetype: "image/jpeg"
  thumbnail: "iVBORw0KGg
  price: 0
  old_price: 0
  label: "Tijdelijke aanbieding"
  quantity: 0


C#
CartProduct cart = new CartProduct();
       cart.cart_id = 1;
       cart.Fetch();

       Response.Write("<pre>" + ObjectDumper.Dump(cart) + "</pre>");


       Product product  = new Product();
       product.product_id = cart.product_id;
       product.Fetch();

       Response.Write("<pre>" + ObjectDumper.Dump(product) + "</pre>");

QuestionMessage Removed Pin
3-Nov-16 14:56
Tung Le Ba Viet3-Nov-16 14:56 
QuestionHow to make hybrid Huffman and RLE compression Pin
Rıza Berkay Ayçelebi2-Nov-16 22:18
Rıza Berkay Ayçelebi2-Nov-16 22:18 
AnswerRe: How to make hybrid Huffman and RLE compression Pin
Pete O'Hanlon2-Nov-16 22:22
mvePete O'Hanlon2-Nov-16 22:22 
AnswerRe: How to make hybrid Huffman and RLE compression Pin
Richard MacCutchan2-Nov-16 22:45
mveRichard MacCutchan2-Nov-16 22:45 
GeneralRe: How to make hybrid Huffman and RLE compression Pin
harold aptroot4-Nov-16 1:29
harold aptroot4-Nov-16 1:29 
Questionhow to capture a screen shot usng c# and asp.net Pin
syedkhaleel20102-Nov-16 21:48
syedkhaleel20102-Nov-16 21:48 
AnswerRe: how to capture a screen shot usng c# and asp.net Pin
Bernhard Hiller2-Nov-16 21:55
Bernhard Hiller2-Nov-16 21:55 
GeneralRe: how to capture a screen shot usng c# and asp.net Pin
syedkhaleel20102-Nov-16 22:04
syedkhaleel20102-Nov-16 22:04 
GeneralRe: how to capture a screen shot usng c# and asp.net Pin
Eddy Vluggen2-Nov-16 22:27
professionalEddy Vluggen2-Nov-16 22:27 
GeneralRe: how to capture a screen shot usng c# and asp.net Pin
syedkhaleel20102-Nov-16 22:39
syedkhaleel20102-Nov-16 22:39 
GeneralRe: how to capture a screen shot usng c# and asp.net Pin
Eddy Vluggen3-Nov-16 0:42
professionalEddy Vluggen3-Nov-16 0:42 
AnswerRe: how to capture a screen shot usng c# and asp.net Pin
Pete O'Hanlon2-Nov-16 22:20
mvePete O'Hanlon2-Nov-16 22:20 
GeneralRe: how to capture a screen shot usng c# and asp.net Pin
syedkhaleel20102-Nov-16 22:40
syedkhaleel20102-Nov-16 22:40 
GeneralRe: how to capture a screen shot usng c# and asp.net Pin
Pete O'Hanlon2-Nov-16 22:51
mvePete O'Hanlon2-Nov-16 22:51 
GeneralRe: how to capture a screen shot usng c# and asp.net Pin
syedkhaleel20102-Nov-16 23:02
syedkhaleel20102-Nov-16 23:02 
GeneralRe: how to capture a screen shot usng c# and asp.net Pin
Pete O'Hanlon2-Nov-16 23:30
mvePete O'Hanlon2-Nov-16 23:30 
QuestionSQL injection prevention Pin
Member 128253812-Nov-16 8:28
Member 128253812-Nov-16 8:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.