更新时出错。错误:没有给出一个或多个必需参数的值

时间:2014-12-10 01:07:40

标签: asp.net gridview aspxgridview

我无法弄清楚如何修复此错误:

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

每当我尝试更新用户的信息时,都会收到此错误消息。我一直试图找出代码中缺少的内容并一直在寻找解决方案。我发现了类似这样的问题,但它有点不同,因为我不太确定应该删除哪一个。

这是代码:

<asp:AccessDataSource ID="AccessDataSource2" runat="server" DataFile="~/App_Data/Geebiz.mdb"
    DeleteCommand="DELETE FROM [tbl_Student] WHERE [Student_Num] = ?" 
    InsertCommand="INSERT INTO [tbl_Student] ([Student_Num], [Team_ID], [Team_Status], 
       [Student_University], [Student_UniCountry], [Student_FullName], [Student_PreferredName], 
       [Student_Email], [Student_Email2], [Student_Address1], [Student_Address2],
       [Student_Address3], [Student_AddressCity], [Student_AddressCountry], 
       [Student_AddressPostcode], [Student_MobileCountryList], [Student_MobilePhone],
       [Student_Facebook], [Student_Skype], [Student_Gender], [Student_CourseRep], 
       [Student_English], [Student_Broadband], [Student_CompAccess], [Recommender_Name], 
       [Recommender_Email], [Recommender_Phone], [Student_Status]) 
    VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"

    SelectCommand="SELECT * FROM [tbl_Student] WHERE ([Student_Num] = ?)" 
    UpdateCommand="UPDATE [tbl_Student] SET [Team_ID] = ?, [Team_Status] = ?, 
    [Student_University] = ?, [Student_UniCountry] = ?, [Student_FullName] = ?, 
    [Student_PreferredName] = ?, [Student_Email] = ?, [Student_Email2] = ?, 
    [Student_Address1] = ?, [Student_Address2] = ?, [Student_Address3] = ?, 
    [Student_AddressCity] = ?, [Student_AddressCountry] = ?, [Student_AddressPostcode] = ?, 
    [Student_MobilePhoneCountryCode] = ?, [Student_MobileCountryList] = ?, [Student_Facebook] = 
    ?, [Student_Skype] = ?, [Student_Gender] = ?, [Student_CourseRep] = ?, [Student_English] = ?,
    [Student_Broadband] = ?, [Student_CompAccess] = ?, [Recommender_Name] = ?, 
    [Recommender_Email] = ?, [Recommender_Phone] = ?, [Student_Status] = ? 
    WHERE [Student_Num] = ?">

    <SelectParameters>
       <asp:ControlParameter ControlID="GridView1" Name="Student_Num"
           PropertyName="SelectedValue" Type="Int32" />
    </SelectParameters>

    <DeleteParameters>
      <asp:Parameter Name="Student_Num" Type="Int32" />
    </DeleteParameters>

我认为错误就在这附近:

  <UpdateParameters>
        <asp:Parameter Name="Team_ID" Type="Int32" />
        <asp:Parameter Name="Team_Status" Type="String" />
        <asp:Parameter Name="Student_University" Type="String" />
        <asp:Parameter Name="Student_UniCountry" Type="String" />
        <asp:Parameter Name="Student_FullName" Type="String" />
        <asp:Parameter Name="Student_PreferredName" Type="String" />
        <asp:Parameter Name="Student_Email" Type="String" />
        <asp:Parameter Name="Student_Email2" Type="String" />
        <asp:Parameter Name="Student_Address1" Type="String" />
        <asp:Parameter Name="Student_Address2" Type="String" />
        <asp:Parameter Name="Student_Address3" Type="String" />
        <asp:Parameter Name="Student_AddressCity" Type="String" />
        <asp:Parameter Name="Student_AddressCountry" Type="String" />
        <asp:Parameter Name="Student_AddressPostcode" Type="String" />
        <asp:Parameter Name="Student_MobileCountryList" Type="String" />
        <asp:Parameter Name="Student_MobilePhone" Type="String" />
        <asp:Parameter Name="Student_Facebook" Type="String" />
        <asp:Parameter Name="Student_Skype" Type="String" />
        <asp:Parameter Name="Student_Gender" Type="String" />
        <asp:Parameter Name="Student_CourseRep" Type="String" />
        <asp:Parameter Name="Student_English" Type="String" />
        <asp:Parameter Name="Student_Broadband" Type="String" />
        <asp:Parameter Name="Student_CompAccess" Type="String" />
        <asp:Parameter Name="Recommender_Name" Type="String" />
        <asp:Parameter Name="Recommender_Email" Type="String" />
        <asp:Parameter Name="Recommender_Phone" Type="String" />
        <asp:Parameter Name="Student_Status" Type="String" />
        <asp:Parameter Name="Student_Num" Type="Int32" />
        </UpdateParameters>

        <InsertParameters>
        <asp:Parameter Name="Student_Num" Type="Int32" />
        <asp:Parameter Name="Team_ID" Type="Int32" />
        <asp:Parameter Name="Team_Status" Type="String" />
        <asp:Parameter Name="Student_University" Type="String" />
        <asp:Parameter Name="Student_UniCountry" Type="String" />
        <asp:Parameter Name="Student_FullName" Type="String" />
        <asp:Parameter Name="Student_PreferredName" Type="String" />
        <asp:Parameter Name="Student_Email" Type="String" />
        <asp:Parameter Name="Student_Email2" Type="String" />
        <asp:Parameter Name="Student_Address1" Type="String" />
        <asp:Parameter Name="Student_Address2" Type="String" />
        <asp:Parameter Name="Student_Address3" Type="String" />
        <asp:Parameter Name="Student_AddressCity" Type="String" />
        <asp:Parameter Name="Student_AddressCountry" Type="String" />
        <asp:Parameter Name="Student_AddressPostcode" Type="String" />
        <asp:Parameter Name="Student_MobileCountryList" Type="String" />
        <asp:Parameter Name="Student_MobilePhone" Type="String" />
        <asp:Parameter Name="Student_Facebook" Type="String" />
        <asp:Parameter Name="Student_Skype" Type="String" />
        <asp:Parameter Name="Student_Gender" Type="String" />
        <asp:Parameter Name="Student_CourseRep" Type="String" />
        <asp:Parameter Name="Student_English" Type="String" />
        <asp:Parameter Name="Student_Broadband" Type="String" />
        <asp:Parameter Name="Student_CompAccess" Type="String" />
        <asp:Parameter Name="Recommender_Name" Type="String" />
        <asp:Parameter Name="Recommender_Email" Type="String" />
        <asp:Parameter Name="Recommender_Phone" Type="String" />
        <asp:Parameter Name="Student_Status" Type="String" />
        </InsertParameters>
</asp:AccessDataSource>

<asp:Label ID="lbl_message2" runat="server" ForeColor="Black">
   Please select a student from the left column first, before you click the 
   continue button in order to update the student detail.
</asp:Label><br />
<asp:Button ID="btn_continue" runat="server" Text="Continue" /><br /><br />
The detail of the student you have selected is shown below:<br />
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
   DataKeyNames="Student_Num" DataSourceID="AccessDataSource2" Height="32px" Width="536px">

<Fields>
<asp:BoundField DataField="Student_Num" HeaderText="Student_Num" InsertVisible="False"
ReadOnly="True" SortExpression="Student_Num" />
<asp:BoundField DataField="Team_ID" HeaderText="Team_ID" SortExpression="Team_ID" />
<asp:BoundField DataField="Team_Status" HeaderText="Team_Status" SortExpression="Team_Status" />
<asp:BoundField DataField="Student_University" HeaderText="Student_University"
   SortExpression="Student_University" />
<asp:BoundField DataField="Student_UniCountry" HeaderText="Student_UniCountry" 
   SortExpression="Student_UniCountry" />
<asp:BoundField DataField="Student_FullName" HeaderText="Student_FullName" 
   SortExpression="Student_FullName" />
<asp:BoundField DataField="Student_PreferredName" HeaderText="Student_PreferredName"
SortExpression="Student_PreferredName" />
<asp:BoundField DataField="Student_Email" HeaderText="Student_Email"
   SortExpression="Student_Email" />
<asp:BoundField DataField="Student_Email2" HeaderText="Student_Email2" 
     SortExpression="Student_Email2" />
<asp:BoundField DataField="Student_Address1" HeaderText="Student_Address1" 
    SortExpression="Student_Address1" />
<asp:BoundField DataField="Student_Address2" HeaderText="Student_Address2" 
     SortExpression="Student_Address2" />
<asp:BoundField DataField="Student_Address3" HeaderText="Student_Address3" 
     SortExpression="Student_Address3" />
<asp:BoundField DataField="Student_AddressCity" HeaderText="Student_AddressCity"
SortExpression="Student_AddressCity" />
<asp:BoundField DataField="Student_AddressCountry" HeaderText="Student_AddressCountry"
SortExpression="Student_AddressCountry" />
<asp:BoundField DataField="Student_AddressPostcode" HeaderText="Student_AddressPostcode"
SortExpression="Student_AddressPostcode" />
<asp:BoundField DataField="Student_MobileCountryList" HeaderText="Student_MobileCountryList"
     SortExpression="Student_MobileCountryList" />
<asp:BoundField DataField="Student_MobilePhone" HeaderText="Student_MobilePhone" 
     SortExpression="Student_MobilePhone" />
<asp:BoundField DataField="Student_Facebook" HeaderText="Student_Facebook" 
     SortExpression="Student_Facebook" />
<asp:BoundField DataField="Student_Skype" HeaderText="Student_Skype" 
     SortExpression="Student_Skype" />
<asp:BoundField DataField="Student_Gender" HeaderText="Student_Gender" 
     SortExpression="Student_Gender" />
<asp:BoundField DataField="Student_CourseRep" HeaderText="Student_CourseRep" 
     SortExpression="Student_CourseRep" />
<asp:BoundField DataField="Student_English" HeaderText="Student_English" 
     SortExpression="Student_English" />
<asp:BoundField DataField="Student_Broadband" HeaderText="Student_Broadband" 
     SortExpression="Student_Broadband" />
<asp:BoundField DataField="Student_CompAccess" HeaderText="Student_CompAccess" 
     SortExpression="Student_CompAccess" />
<asp:BoundField DataField="Recommender_Name" HeaderText="Recommender_Name" 
     SortExpression="Recommender_Name" />
<asp:BoundField DataField="Recommender_Email" HeaderText="Recommender_Email" 
     SortExpression="Recommender_Email" />
<asp:BoundField DataField="Recommender_Phone" HeaderText="Recommender_Phone" 
     SortExpression="Recommender_Phone" />
<asp:BoundField DataField="Student_Status" HeaderText="Student_Status" 
     SortExpression="Student_Status" />
<asp:CommandField ShowEditButton="True" />
</Fields>
</asp:DetailsView>

1 个答案:

答案 0 :(得分:0)

UpdateCommand中参数的顺序应与UpdateParameters中的相同。另外,请检查UpdateParameter列表中缺少[Student_MobilePhoneCountryCode]