Click here to Skip to main content
16,013,605 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i just want to calculate the ratings based in the product and display five recommended product based on the rating i done all the things by using below code ...but i have one problem while i executing the code lost product details only displayed in that top five model so i need to separate the string and assign that into different string or array based on that i need to retrieve the data about that top five product details fro database
---------------------------
Code for rating calculation:
----------------------------
C#
try
{
     con1.Open();
     SqlCommand cmd1 = new SqlCommand("select top 5 model, sum(rating)/count(name) as ratetotal,count(name) as nocustomer from ratings where ptype='laptop' GROUP BY  model order by ratetotal desc", con1);

     SqlDataReader rdr = cmd1.ExecuteReader();
 
     while (rdr.Read())
     {
         lap.Add(rdr[0].ToString());
         //lapt.Add(rdr[0].ToString());
         //lapt.Add(rdr[1].ToString());
         //lapt.Add(rdr[2].ToString());
        //lap.Add(lapt.ToString());
     }           
}

---------------------------------------
code for retrieve the data from database:
C#
ArrayList dat = ratingdata.rating.laprating();
string model;
       
foreach (object x in dat)
{
     model = x.ToString();
     string[] modelna = model.Split(',');
     string first = modelna[0].ToString();
 
     try
     {
          con.Open();
          SqlCommand cmds = new SqlCommand("select Pictureurl,pbrandname,model,price from productdetails where model=@model", con);
          cmds.Parameters.AddWithValue("@model",model.ToString());
          SqlDataAdapter das = new SqlDataAdapter(cmds);
          DataSet dsa = new DataSet();
          das.Fill(dsa, "productdetails");
          DataList2.DataSource = dsa.Tables[0];
          DataList2.DataBind();
}

============================================================
Posted
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900