0

Problem:

I'm new to ASP.Net and I need some guidelines where to start, and what to do? I have read couple of the articles I found on different sites. But, some are not using VB code and I'm not confident of my C# coding knowledge.

I have included a table from my database and a PHP code to help visualize what I wanted to create.

My Table

    ------------------------------------------------------------------------------------------
    |  items_id   |  items_name  |      items_description     | items_price | items_quantity |
    ------------------------------------------------------------------------------------------
    |     1       |    Spoon     |       Shiny and Silver     |     50      |       20       |
    |     2       |     Fork     |       Shiny and Silver     |     50      |       20       |
    |     3       |    China     |      Clean and Polished    |     90      |       20       |
    ------------------------------------------------------------------------------------------

PHP Code

    $sql = mysql_query("SELECT * FROM tbl_items");
    $productCount = mysql_num_rows($sql); 
    if ($productCount > 0) {
        while($row = mysql_fetch_array($sql)){ 
                 $id = $row["items"];
                 $name = $row["items_name"];
                 $description = $row["items_description"];
                 $price = $row["items_price"];
                 $quantity = $row["items_quantity"];
                 $check_pic = 'venues/'.$id.'/'.$id.'.jpg';
                if (file_exists($check_pic)) {
                    $img_src = 'venues/'.$id.'/'.$id.'.jpg';
                    } else {
                    $img_src = 'venues/0/0.jpg'; 
                }

                 $dynamicList .= '<li class="span3">
                    <div class="thumbnail">
                        <p><b>'.$name. '</b></p><br />
                       <img src="'.$img_src.'" alt="" style="box-shadow: 0 2px 3px rgba(0,0,0,0.2);">
                      <div class="caption">
                         <p align="center" class="lead" style="color:#053750;"> '.$venue.'</p> 
                          <hr />
                        <p><b>Description: </b> '.$description. '</p><br />
                        <p><b>Price: </b> '.$price. '</p><br />
                        <p><b>Quantity: </b> '.$quantity. '</p><br />
                        <p><a href="items_details.php?items_id='.$id.'" class="btn btn-info btn-block">Choose</a> </p>
                      </div>
                    </div>
                  </li>';
        }

Some articles I have read:


Part 4: Listing Products - The ASP parts are very comprehensible but, I don't know how to replace it's connection to the database to ODBC.

Binding a generic list to a repeater - ASP.NET - The behind codes are C# and I'm having a hard time converting even with the help of C# to VB converter

Community
  • 1
  • 1
Kyo Yamagata
  • 25
  • 2
  • 6

1 Answers1

0

The most straightforward mapping from your PHP code to .NET code would be to use a library like this: http://www.mysql.com/products/connector/

Use the MySqlConnection class to connect to your DB server, the MySqlCommand class to build your query, and the MySqlDataReader to iterate over the results and build your markup.

That will get you up and running, and then if you want to investigate .NET's binding to repeaters or other controls, you can work from there.

joelt
  • 2,632
  • 2
  • 19
  • 32
  • Will it be the same if I use ODBC? My Database Hosting uses ODBC Driver 3.5.1 – Kyo Yamagata Mar 17 '13 at 23:51
  • It seems like your web host's software would matter more than your DB host's driver software. But you could also try the built-in ODBC namespace http://msdn.microsoft.com/en-us/library/system.data.odbc.aspx. The classes are named similarly to the MySql ones I mentioned earlier. – joelt Mar 18 '13 at 00:15