Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm having a problem with my code that i've been trying to fix for hours now. Basically, the goal of the program is for users to log in, then they can fill in basically a movie review page. Theoretically every user is only allowed to leave one review for each movie - though I haven't gotten to the validation for that yet. Right now, it just keeps saying that there's no value given for one of the parameters so if anyone could help out that would be amazing. 

Code: 
C#
<form id="form1" runat="server">
<div>

<asp:GridView ID="GridReview" runat="server" AutoGenerateColumns="False" DataKeyNames="movieid" DataSourceID="SqlDataSource1">
<Columns> <asp:BoundField DataField="movietitle" HeaderText="movietitle" InsertVisible="False" ReadOnly="false" SortExpression="movietitle" />

<asp:BoundField DataField="Username" HeaderText="User" SortExpression="Username" />
<asp:BoundField DataField="review" HeaderText="Review" SortExpression="review" />
<asp:BoundField DataField="rating" HeaderText="Rating" SortExpression="rating" />
</Columns>
</asp:GridView>

<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="movieid" DataSourceID="SqlDataSource1" DefaultMode="Insert" Height="50px" Width="125px" OnItemInserted="DetailsView1_ItemInserted">
<Fields>
<asp:TemplateField HeaderText="MovieTitle" SortExpression="Movieid">
<ItemTemplate>
<asp:DropDownList runat="server" DataSourceID="SqlDataSourceW2" DataTextField="MovieTitle" DataValueField="MovieId"></asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSourceW2" runat="server" ConnectionString="<%$ ConnectionStrings:Database1connectionString %>" ProviderName="<%$ ConnectionStrings:Database1connectionString.ProviderName %>" SelectCommand="SELECT [MovieID], [MovieTitle] FROM [movies_table] ORDER BY [Movietitle]"></asp:SqlDataSource>
</ItemTemplate> 
</asp:TemplateField>
<asp:BoundField DataField="rating" HeaderText="rating" SortExpression="rating" />
<asp:BoundField DataField="review" HeaderText="review" SortExpression="review" />

<asp:CommandField ShowInsertButton="True" />
</Fields>
</asp:DetailsView>

</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Database1ConnectionString %>" SelectCommand="select * from REVIEW_TABLE where (movieid = ?)" InsertCommand="insert [REVIEW_TABLE]
([Username], [MovieID], [MovieTitle], [Rating], [Review])
values (?,?,?,?,?)" ProviderName="<%$ ConnectionStrings:Database1ConnectionString.ProviderName %>" >



<InsertParameters>
<asp:SessionParameter Name="Username" SessionField="Username" Type="String" />
<asp:Parameter Name="movieid" Type="String" />
<asp:Parameter Name="movietitle" Type="String" />
<asp:Parameter Name="rating" Type="String" />
<asp:Parameter Name="review" Type="String" />
</InsertParameters>
</asp:SqlDataSource>




<asp:Label ID="LabelError" runat="server"></asp:Label>
</form>



here's the code behind 

C#
protected void Page_Load(object sender, EventArgs e)
{
if (Session["firstname"] == null)
{
Response.Redirect("login.aspx");
Session["UserName"] = HttpContext.Current.User.Identity.Name;
}
}

protected void DetailsView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
{

GridReview.DataBind();



}



and here's the error I keep getting
Server Error in '/' Application.
No value given for one or more required parameters.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Data.OleDb.OleDbException: No value given for one or more required parameters.

Source Error: 


An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[OleDbException (0x80040e10): No value given for one or more required parameters.]
   System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) +1144656
   System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +247
   System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +208
   System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +58
   System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +162
   System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior) +110
   System.Data.OleDb.OleDbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) +9
   System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +139
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +136
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +86
   System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1474
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +22
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +143
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74
   System.Web.UI.WebControls.GridView.DataBind() +9
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +114
   System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +75
   System.Web.UI.Control.EnsureChildControls() +92
   System.Web.UI.Control.PreRenderRecursiveInternal() +42
   System.Web.UI.Control.PreRenderRecursiveInternal() +160
   System.Web.UI.Control.PreRenderRecursiveInternal() +160
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +883


What I have tried:

honestly i've lost track of all the things i've tried at this point.
Posted
Updated 6-May-18 17:10pm
Comments
Bryian Tan 6-May-18 22:39pm    
The code is setting the session variable "UserName" but the parameter is trying to retrieve "Username". I think that the issue, case sensitive.

Just curious, where Session["firstname"] being set? or will it be null all the time?
Member 13814497 6-May-18 22:48pm    
I made all the "Username"'s into "UserName" but i'm still getting the same error, unfortunately.

The Session["firstname"] comes from the login form's code behind.
Bryian Tan 6-May-18 22:57pm    
Anyway, these line doesn't make sense. The Session["UserName"] never get reached because if if firstname is null redirect to login page. Where the Session["UserName"] get populated?
if (Session["firstname"] == null)
{
    Response.Redirect("login.aspx");
    Session["UserName"] = HttpContext.Current.User.Identity.Name;
}

1 solution

As far as I can see you haven't defined the SelectParameters at all. However, you have a parameter in the select command:
SelectCommand="select * from REVIEW_TABLE where (movieid = ?)"
 
Share this answer
 
Comments
Maciej Los 7-May-18 13:45pm    
Hawk eye!

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