Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
i got error Specified cast is not valid.i need to repeat every user already rating star from database how to get rating from db.here how to take rating from database.

stored procedure

SQL
ALTER PROCEDURE [dbo].[sp_comments]
(
@eid int
)
AS
BEGIN
	declare @sql varchar(max)
	SET NOCOUNT ON;

	select @sql='select g.username,dbo.fn_username(g.updation) as updation,
	c.comment_id,c.id,c.comments,c.commented_by,c.mail,c.date,c.rating_star
	from comments c
	inner join tbl_data as g on g.id=c.id
	WHERE c.id=''' +CONVERT(VARCHAR(50),@eid) +''' order by comment_id desc'
	exec(@sql)
	print(@sql)

END


asp.net design page

ASP.NET
<asp:Rating ID="user_rating" runat="server" CurrentRating='<%#Eval("rating_star")%>' RatingDirection="LeftToRightTopToBottom" StarCssClass="ratingStar" WaitingStarCssClass="SavedRatingStar" FilledStarCssClass="FilledRatingStar" 
EmptyStarCssClass="EmptyRatingStar" AutoPostBack="true">


C# page

C#
protected void Button1_Click(object sender, EventArgs e)

    {
        if (Request.QueryString["id"] != null) 
        { 
        int id;
        id = Convert.ToInt32(Request.QueryString["id"].ToString());

        con = new SqlConnection(str);
        con.Open();
        cmd = new SqlCommand("sp_usercomment", con);
        cmd.CommandType = CommandType.StoredProcedure;   
        cmd.Parameters.AddWithValue("@mail", mail_by.Text);
        cmd.Parameters.AddWithValue("@comments", comments.Text);
        cmd.Parameters.AddWithValue("@name", name_by.Text);
        cmd.Parameters.AddWithValue("@updated_name", Convert.ToInt32(Request.Cookies["userid"].Value));
        cmd.Parameters.AddWithValue("@eid",id);
        cmd.Parameters.AddWithValue("@rating",SqlDbType.Int).Value=rating.CurrentRating;
        cmd.ExecuteNonQuery();
        con.Close();
        Label2.Visible = true;
        Label2.Text = "Thanks for your valuable feedback";
        
        mail_by.Text = "";
        comments.Text = "";
        name_by.Text= "";


        getcomments();
        }
    }


 void getcomments()

    {
        con = new SqlConnection(str);
        con.Open();
        cmd = new SqlCommand("sp_comments", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add(new SqlParameter("@eid", Request.QueryString["id"].ToString()));
        da=new SqlDataAdapter(cmd);
        dt = new DataTable();
        da.Fill(dt);
        con.Close();
       
        comment_label.Text = "View " + dt.Rows.Count.ToString() + " Comments";
        if (dt.Rows.Count > 0)
        {
            DataRow dr=dt.Rows[0];
            repeat.DataSource = dt.DefaultView;
            repeat.DataBind();
            review_panel.Visible = true;
            product = dr["username"].ToString();
            
           
        }
        else
        {
            review_panel.Visible = false;
        }
    }
Posted
Updated 11-Feb-15 23:39pm
v2
Comments
Sinisa Hajnal 12-Feb-15 5:05am    
Which line? In the code or in the query? This should be easy to debug, just find the source and cast it properly.

Since you're using integer, why is your c.id varchar? Change it into int field and you don't have to cast at all.
Member 10918596 12-Feb-15 5:39am    
pls give brief explantion and give example for this one
Herman<T>.Instance 12-Feb-15 5:42am    
You don't now how to set breakpoints and debug your code? Google for that first then.
Member 10918596 12-Feb-15 5:52am    
there are no solution in google already i searched...

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