Answered by:
No Value Given for one or more required parameters

Question
-
User1974778355 posted
Hello, Im studying asp.net 2 and I want to know why i'm getting this error when I click the update in the gridview.
this is my asp.net page
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="studentId" DataSourceID="AccessDataSource1">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="studentId" HeaderText="studentId"
InsertVisible="False" ReadOnly="True" SortExpression="studentId" />
<asp:BoundField DataField="Lastname" HeaderText="Lastname"
SortExpression="Lastname" />
<asp:BoundField DataField="Firstname" HeaderText="Firstname"
SortExpression="Firstname" />
</Columns>
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
ConflictDetection="CompareAllValues" DataFile="~/App_Data/guide_db.mdb"
DeleteCommand="DELETE FROM [students] WHERE [studentId] = ? AND (([Lastname] = ?) OR ([Lastname] IS NULL AND ? IS NULL)) AND (([Firstname] = ?) OR ([Firstname] IS NULL AND ? IS NULL))"
InsertCommand="INSERT INTO [students] ([studentId], [Lastname], [Firstname]) VALUES (?, ?, ?)"
OldValuesParameterFormatString="original_{0}"
SelectCommand="SELECT [studentId], [Lastname], [Firstname] FROM [students]"
UpdateCommand="UPDATE [students] SET [Lastname] = ?, [Firstname] = ? WHERE [studentId] = ? AND (([Lastname] = ?) OR ([Lastname] IS NULL AND ? IS NULL)) AND (([Firstname] = ?) OR ([Firstname] IS NULL AND ? IS NULL))">
<DeleteParameters>
<asp:Parameter Name="original_studentId" Type="Int32" />
<asp:Parameter Name="original_Lastname" Type="String" />
<asp:Parameter Name="original_Firstname" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="Lastname" Type="String" />
<asp:Parameter Name="Firstname" Type="String" />
<asp:Parameter Name="original_studentId" Type="Int32" />
<asp:Parameter Name="original_Lastname" Type="String" />
<asp:Parameter Name="original_Firstname" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="studentId" Type="Int32" />
<asp:Parameter Name="Lastname" Type="String" />
<asp:Parameter Name="Firstname" Type="String" />
</InsertParameters>
</asp:AccessDataSource>
</div>
</form>
</body>
</html>and im getting this when i run the website and clicking the edit>> update button
Server Error in '/Guidance_eval' 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) +992108
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +255
System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +188
System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +58
System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +161
System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +113
System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand command, DataSourceOperation operation) +386
System.Web.UI.WebControls.SqlDataSourceView.ExecuteDelete(IDictionary keys, IDictionary oldValues) +303
System.Web.UI.DataSourceView.Delete(IDictionary keys, IDictionary oldValues, DataSourceViewOperationCallback callback) +89
System.Web.UI.WebControls.GridView.HandleDelete(GridViewRow row, Int32 rowIndex) +714
System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +869
System.Web.UI.WebControls.GridView.RaisePostBackEvent(String eventArgument) +207
System.Web.UI.WebControls.GridView.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +156Please tell me why Im getting these error, My Primary key in my database is the studentId(text 255). I only encounter these using MS Access Database, but in SQL SERVER it works fine..
Please Help.. I appcreciate if someone would let me know why im getting these exception.
Monday, September 5, 2011 8:41 PM
Answers
-
User-1199946673 posted
When using ? as parameter, each one is threaded as a seperate parameter. But in you updatecommand, you use 7 questionmarks, but only specify 5, because your intention is to use some parameters twice. You can solve this to ways. Specify 7 parameters in the order they appear in the update statement. You can use the same parameter twice if needed:
A better option is to use named parameters in your updatecommand.
UpdateCommand="UPDATE [students] SET [Lastname] = @Lastname, [Firstname] = @Firstname WHERE [studentId] = @StudentId AND (([Lastname] = @original_Lastname) OR ([Lastname] IS NULL AND @Lastname IS NULL)) AND (([Firstname] = @orignal_Firstname) OR ([Firstname] IS NULL AND @Firstname IS NULL))"
This way, Access understands that some parameters are need to be used twice....
By the way. Are you sure that you want to use CompareAllValues? It makes you query's much more complex because you need the optional parameters...
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, September 6, 2011 3:17 AM -
User-1199946673 posted
I want to use two primary keys. the studentId and the schoolyear column will be my primary keys..I want the studentId and schoolyear column updatablePrimary Keys shouldn't be updatable. Just Add another autonumber field and make that field your primary key.
The reason why your update won't work is simple:
If you change either sudentId or schoolyear, the WHERE clause will not match and no records will be updated...
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, September 7, 2011 2:53 AM
All replies
-
User560751820 posted
check this..
Tuesday, September 6, 2011 1:36 AM -
User-1199946673 posted
When using ? as parameter, each one is threaded as a seperate parameter. But in you updatecommand, you use 7 questionmarks, but only specify 5, because your intention is to use some parameters twice. You can solve this to ways. Specify 7 parameters in the order they appear in the update statement. You can use the same parameter twice if needed:
A better option is to use named parameters in your updatecommand.
UpdateCommand="UPDATE [students] SET [Lastname] = @Lastname, [Firstname] = @Firstname WHERE [studentId] = @StudentId AND (([Lastname] = @original_Lastname) OR ([Lastname] IS NULL AND @Lastname IS NULL)) AND (([Firstname] = @orignal_Firstname) OR ([Firstname] IS NULL AND @Firstname IS NULL))"
This way, Access understands that some parameters are need to be used twice....
By the way. Are you sure that you want to use CompareAllValues? It makes you query's much more complex because you need the optional parameters...
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, September 6, 2011 3:17 AM -
User1974778355 posted
Thanks hans_v.
But i gor another problem again. I made some changes, I want to use two primary keys. the studentId and the schoolyear column will be my primary keys..
'see codes below
'+================================================================================================+
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="studentId,schoolyear" DataSourceID="AccessDataSource1">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="studentId" HeaderText="studentId"
SortExpression="studentId" ConvertEmptyStringToNull="False" />
<asp:BoundField DataField="Lastname" HeaderText="Lastname"
SortExpression="Lastname" />
<asp:BoundField DataField="Firstname" HeaderText="Firstname"
SortExpression="Firstname" />
<asp:BoundField DataField="schoolyear" HeaderText="schoolyear"
SortExpression="schoolyear" ConvertEmptyStringToNull="False" />
</Columns>
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/guide_db.mdb"
DeleteCommand="DELETE FROM [students] WHERE [studentId] = ? AND [schoolyear] = ?"
InsertCommand="INSERT INTO [students] ([studentId], [Lastname], [Firstname], [schoolyear]) VALUES (?, ?, ?, ?)"
SelectCommand="SELECT * FROM [students]"
UpdateCommand="UPDATE [students] SET [studentId]=@studentId, [Lastname] = @Lastname, [Firstname] = @Firstname, [schoolyear]=@schoolyear WHERE [studentId] = @studentId AND [schoolyear] = @schoolyear">
<DeleteParameters>
<asp:Parameter Name="studentId" Type="String" />
<asp:Parameter Name="schoolyear" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="Lastname" Type="String" />
<asp:Parameter Name="Firstname" Type="String" />
<asp:Parameter Name="studentId" Type="String" />
<asp:Parameter Name="schoolyear" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="studentId" Type="String" />
<asp:Parameter Name="Lastname" Type="String" />
<asp:Parameter Name="Firstname" Type="String" />
<asp:Parameter Name="schoolyear" Type="Int32" />
</InsertParameters>
</asp:AccessDataSource>
</div>
</form>
</body>
</html>'+===============================================================================================+
I want the studentId and schoolyear column updatable and I already include it to the update command and also in the Edit Columns of the gridview i also set the readonly=false and convertemptystringtonull=false.
I received no error when running the page, but instead, the update won't work, it shows me the same data when i edit the values in schoolyear and studentId column.
Hope I can get many tutorials so I can be familiar to asp.net VB. What books should you prefer to read?, as of now, I am reading asp.net 2.0 in 24hours by sams teachyourself.
Im very trying hard to learn asp.net.
I want to learn it fast. ^_^
Tuesday, September 6, 2011 8:36 PM -
User1974778355 posted
i dont intend to use these parameters
<asp:Parameter Name="original_studentId" Type="Int32" />
<asp:Parameter Name="original_Lastname" Type="String" />
<asp:Parameter Name="original_Firstname" Type="String" />im sorry, i didnt see it, it was computer generated and im still lack of in coding the page. that's why i want to learn it.asp.net 2.0 is new to me, that's why i want to learn and understand it very well.
Tuesday, September 6, 2011 8:53 PM -
User-1199946673 posted
I want to use two primary keys. the studentId and the schoolyear column will be my primary keys..I want the studentId and schoolyear column updatablePrimary Keys shouldn't be updatable. Just Add another autonumber field and make that field your primary key.
The reason why your update won't work is simple:
If you change either sudentId or schoolyear, the WHERE clause will not match and no records will be updated...
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, September 7, 2011 2:53 AM -
User1974778355 posted
thank you hans_v. i know now why it does'nt work. thanks a lot. whats the best book that i could buy for studying asp.net VB?
Saturday, September 10, 2011 7:30 AM