Jump to content
Xtreme .Net Talk

fasil

Members
  • Posts

    16
  • Joined

  • Last visited

About fasil

  • Birthday 08/12/1976

Personal Information

  • Occupation
    Developer
  • Visual Studio .NET Version
    Visual Studio .NET Professional
  • .NET Preferred Language
    C#

fasil's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. Here is the deal: 1. I have an image extracted out from a database through a SQL statement. ex. SELECT IMG_DATA FROM tblIMAGE WHERE ID = 1 I need to stream the IMG_DATA on a page binding it to a <IMG> tag. How do I do this?
  2. I have presented my data retrieved from a DB in a repeater. unfortunately there are too many rows too show on one page. How can I allow paging when in a repeater? ################Code################# <table border="0" cellspacing="0" cellpadding="0" width="100%" class="listText"> <asp:Repeater ID="productlist" runat="server" EnableViewState="true"> <HeaderTemplate> <tr class="listHeader"> <td>#pic#</td><td>Navn</td><td align="right">Pris</td><td align="center">Kurv</th> </tr> </HeaderTemplate> <ItemTemplate> <tr> <td> <img src="" /> </td> <td> <a href="produkt.aspx"> <%# DataBinder.Eval(Container.DataItem, "ProductName")%> </a> </td> <td align="right"> <%# DataBinder.Eval(Container.DataItem, "ProductPrice") %> kr. </td> <td align="center"> <a href="#">Tilføj</a> </td> </tr> </ItemTemplate> <AlternatingItemTemplate> <tr bgcolor="lightblue"> <td> <img src="" /> </td> <td> <a href="produkt.aspx"> <%# DataBinder.Eval(Container.DataItem, "ProductName")%> </a> </td> <td align="right"> <%# DataBinder.Eval(Container.DataItem, "ProductPrice") %> kr. </td> <td align="center"> <a href="#">Tilføj</a> </td> </tr> </AlternatingItemTemplate> </asp:Repeater> </table> ################################## I can only see the 'AllowPaging' property for datagrids, how can I use paging functionality in a repeater. SHow me an example please.
  3. But what about the last one which is a decimal. I tried (decimal) rdr["product_price"]; There was no compilation error but it gave an error when calling the page.
  4. Then what about... p.ProductName = rdr["product_name"].ToString(); p.ProductPrice = Convert.ToDecimal(rdr["product_price"]);
  5. I am very glad for all the input. But could someone at least correct my code in such a fashion it is flawless, and put in some comments on why such code is better.
  6. Actually I close my reader in my DBConnector class, maybe it should also be evaluated here. ----------------------------------------------------------- using MySql; using MySql.Data; using MySql.Data.MySqlClient; using System.Data; /// <summary> /// Summary description for dbConnector. /// Datbaseconnector /// </summary> public class DbConnector { private const string strConn = "Database=ecommerce;Data Source=localhost;User Id=root;Password=skywalker"; private MySqlConnection _connection; protected MySqlConnection SqlConnection { get { if(_connection == null) _connection = new MySqlConnection(strConn); return _connection; } } public MySqlDataReader DbConnect(string strSql) { MySqlConnection SqlConnection = new MySqlConnection(strConn); SqlConnection.Open(); MySqlCommand sel = new MySqlCommand(strSql, SqlConnection); MySqlDataReader rdr = sel.ExecuteReader(CommandBehavior.CloseConnection); return rdr; } public void DbClose() { SqlConnection.Close(); } }
  7. I am very glad for the information. Actually I am quite new i c# and .net, and I am very familiar with some of the errors u have mentioned. I it wouldn't be so much for u, can u post back your version of this code. I will be really glad, if you also put in some of the above mentioned flaws as comments in your corrected version. I thought I had layered it correctly, but that is why I want to listen from the real experts in here, and get my code evaluated.
  8. Than u very much...
  9. Maybe someone can also tell me why _variables are so popular....
  10. Glad for some inputs. The coce is fully functional, and yes I am familiar with SQL server Stored Procedures. But I am using MySql 4.0 and therefore I can only make use of 'inline' sql querys and concatenations
  11. Would anyone here please evaluate my code? Is there something I am doing terribly wrong? using System; using System.Collections; using MySql; using MySql.Data; using MySql.Data.MySqlClient; public class ProductData { private int _ProductId; private string _ProductName; private decimal _ProductPrice; //Properties public ProductData() { } public int ProductId { get { return _ProductId;} set { _ProductId = value;} } public string ProductName { get { return _ProductName;} set { _ProductName = value;} } public decimal ProductPrice { get { return _ProductPrice;} set { _ProductPrice = value;} } } /// <summary> /// Summary description for Product. /// </summary> public class Product { public Product() { } public ArrayList GetProductSearchLst(string SoegStreng) { String strSql = "SELECT id as product_id, Name as product_name, Price as product_price FROM product WHERE NAME LIKE '%"+ SoegStreng + "%' ORDER BY NAME;"; DbConnector dbCon = new DbConnector(); MySqlDataReader rdr = dbCon.DbConnect(strSql); ArrayList arrLstProduct = new ArrayList(); while (rdr.Read()) { ProductData p = new ProductData(); p.ProductId = Convert.ToInt32(rdr["product_id"]); p.ProductName = rdr["product_name"].ToString(); p.ProductPrice = Convert.ToDecimal(rdr["product_price"]); arrLstProduct.Add(p); } dbCon.DbClose(); return arrLstProduct; } public ArrayList GetProduct(int ProductId) { String strSql = "SELECT id as product_id, Name as product_name, Price as product_price FROM product WHERE ID = "+ ProductId + ""; DbConnector dbCon = new DbConnector(); MySqlDataReader rdr = dbCon.DbConnect(strSql); ArrayList arrLstProduct = new ArrayList(); ProductData p = new ProductData(); p.ProductId = Convert.ToInt32(rdr["product_id"]); p.ProductName = rdr["product_name"].ToString(); p.ProductPrice = Convert.ToDecimal(rdr["product_price"]); arrLstProduct.Add(p); dbCon.DbClose(); return arrLstProduct; } }
  12. I am trying loo through a ArrayList, but how do I get the length of the ArrayList, u know what in vbscript is Ubound(array). CartContent a = new CartContent(); ArrayList cardArray = a.GetCart(); foreach (?????){ PageMsg.Text += "Count this sentence to see how many elements"; }
  13. Okay but what about the rest?
  14. 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; } }
  15. Hi there I still consider myself a newb, eventhough I have been programming asp for some years. But I still think that I can be much better :) I have been working hard to split my code in layers. #Presentation# #business/logic# #Database# But I still think that my programming style can be a lot better. I dont read or buy so many books, bcuz most of the information is available on the Internet. Therefor there will be some deep questions from me and I am suer that there will be alot of stupid questions too. I hope that I also can use this forum to get my programming evaluated and perspectivated. :) A lot of respect to everybody in here from me. I will start my first series of questions very soon. Regards Fasil
×
×
  • Create New...