Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 4.5.1 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4.5.1: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-84677-3
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4.5.1 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 14th, 2014, 02:22 AM
Registered User
 
Join Date: May 2014
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Smile Please help

Dear imar sir...I wanna to work with rating control in AjaxToolkit Liabrery. I searched on google and got some code...
Code:
public partial class Demo_Default : System.Web.UI.Page
{ SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["CloudShopConnectionString1"].ConnectionString);
    
protected void RatingControlChanged(object sender, AjaxControlToolkit.RatingEventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("insert into RatingDetails(Rate)values(@Rating)",con);
cmd.Parameters.AddWithValue("@Rating",Rating1.CurrentRating);
cmd.ExecuteNonQuery();
con.Close();
BindRatingControl();
}
protected void BindRatingControl()
{
    int total = 0;

    DataTable dt = new DataTable();
    con.Open();
    SqlCommand cmd = new SqlCommand("Select Rate from RatingDetails", con);
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    da.Fill(dt);
    if (dt.Rows.Count > 0)
    {
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            total += Convert.ToInt32(dt.Rows[i][0].ToString());
        }
        int average = total / (dt.Rows.Count);
        Rating1.CurrentRating = average;

        Label1.Text = Convert.ToInt32(total).ToString();
       
        lbltxt.Text = dt.Rows.Count + "user(s) have rated this article";
    }
}
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
            {
                BindRatingControl();
            }
    }
}
As it working fine...but as i rate anything..It creates a new row in database and inserts rating values..
Please make some changes in the code that it updates the frist row instead of creating new row each time...Ihanks in advance
 
Old September 14th, 2014, 07:50 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Since this is not related to my book directly, please post this in the General ASP.NET category here: http://p2p.wrox.com/asp-net-4-5-1-752/ This way you'll attract more viewers.

That said, you need to update your SQL code to query an existing record first and update it if it exists, otherwise insert a new record.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old September 14th, 2014, 01:18 PM
Registered User
 
Join Date: May 2014
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Mr Imar









Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.