Hi all, I am using Visual Studio 2005, I have created a web application that uses a Grid View with a Delete, Update, insert commmand field. But I am getting the following error when I try to delete a record:
Must declare the variable '@FAQ1ID'.
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.SqlClient.SqlException: Must declare the variable '@FAQ1ID'.
This is my code:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Edit1.ascx.cs" Inherits="CMSWebParts_MyWebParts_Edit1" %>
<asp:GridView ID="GridView1" runat="server" AutoGenerateDeleteButton="True" AutoGenerateEditButton="True"
AutoGenerateSelectButton="True" DataSourceID="SqlDataSource1" DataKeyNames="FAQ1ID">
<Columns>
<asp:BoundField DataField="FAQ1ID" HeaderText="FAQ1ID" InsertVisible="False" ReadOnly="True"
SortExpression="FAQ1ID" />
<asp:BoundField DataField="FormInserted" HeaderText="FormInserted" SortExpression="FormInserted" />
<asp:BoundField DataField="Area" HeaderText="Area" SortExpression="Area" />
<asp:BoundField DataField="Topic" HeaderText="Topic" SortExpression="Topic" />
<asp:BoundField DataField="Issue" HeaderText="Issue" SortExpression="Issue" />
<asp:BoundField DataField="Update" HeaderText="Update" SortExpression="Update" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="OverwriteChanges"
ConnectionString="<%$ ConnectionStringsSCEMEAWEB_BConnectionString4 %>"
DeleteCommand="DELETE FROM [TBL_FAQ1] WHERE [FAQ1ID] = @FAQ1ID AND [FormInserted] = @original_FormInserted AND [Area] = @original_Area AND [Topic] = @original_Topic AND [Issue] = @original_Issue AND [Update] = @original_Update"
InsertCommand="INSERT INTO [TBL_FAQ1] ([FormInserted], [Area], [Topic], [Issue], [Update]) VALUES (@FormInserted, @Area, @Topic, @Issue, @Update)"
OldValuesParameterFormatString="original_{0}"
SelectCommand="SELECT [FAQ1ID], [FormInserted], [Area], [Topic], [Issue], [Update] FROM [TBL_FAQ1] WHERE ([Area] = @Area)"
UpdateCommand="UPDATE [TBL_FAQ1] SET [FormInserted] = @FormInserted, [Area] = @Area, [Topic] = @Topic, [Issue] = @Issue, [Update] = @Update WHERE [FAQ1ID] = @original_FAQ1ID AND [FormInserted] = @original_FormInserted AND [Area] = @original_Area AND [Topic] = @original_Topic AND [Issue] = @original_Issue AND [Update] = @original_Update">
<SelectParameters>
<asparameter DefaultValue="CXP" Name="Area" Type="String" />
</SelectParameters>
<DeleteParameters>
<asparameter Name="original_FAQ1ID" Type="Int32" />
<asparameter Name="original_FormInserted" Type="DateTime" />
<asparameter Name="original_Area" Type="String" />
<asparameter Name="original_Topic" Type="String" />
<asparameter Name="original_Issue" Type="String" />
<asparameter Name="original_Update" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asparameter Name="FormInserted" Type="DateTime" />
<asparameter Name="Area" Type="String" />
<asparameter Name="Topic" Type="String" />
<asparameter Name="Issue" Type="String" />
<asparameter Name="Update" Type="String" />
<asparameter Name="original_FAQ1ID" Type="Int32" />
<asparameter Name="original_FormInserted" Type="DateTime" />
<asparameter Name="original_Area" Type="String" />
<asparameter Name="original_Topic" Type="String" />
<asparameter Name="original_Issue" Type="String" />
<asparameter Name="original_Update" Type="String" />
</UpdateParameters>
<InsertParameters>
<asparameter Name="FormInserted" Type="DateTime" />
<asparameter Name="Area" Type="String" />
<asparameter Name="Topic" Type="String" />
<asparameter Name="Issue" Type="String" />
<asparameter Name="Update" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
Thanks in advance!
Must declare the variable '@FAQ1ID'.
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.SqlClient.SqlException: Must declare the variable '@FAQ1ID'.
This is my code:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Edit1.ascx.cs" Inherits="CMSWebParts_MyWebParts_Edit1" %>
<asp:GridView ID="GridView1" runat="server" AutoGenerateDeleteButton="True" AutoGenerateEditButton="True"
AutoGenerateSelectButton="True" DataSourceID="SqlDataSource1" DataKeyNames="FAQ1ID">
<Columns>
<asp:BoundField DataField="FAQ1ID" HeaderText="FAQ1ID" InsertVisible="False" ReadOnly="True"
SortExpression="FAQ1ID" />
<asp:BoundField DataField="FormInserted" HeaderText="FormInserted" SortExpression="FormInserted" />
<asp:BoundField DataField="Area" HeaderText="Area" SortExpression="Area" />
<asp:BoundField DataField="Topic" HeaderText="Topic" SortExpression="Topic" />
<asp:BoundField DataField="Issue" HeaderText="Issue" SortExpression="Issue" />
<asp:BoundField DataField="Update" HeaderText="Update" SortExpression="Update" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="OverwriteChanges"
ConnectionString="<%$ ConnectionStringsSCEMEAWEB_BConnectionString4 %>"
DeleteCommand="DELETE FROM [TBL_FAQ1] WHERE [FAQ1ID] = @FAQ1ID AND [FormInserted] = @original_FormInserted AND [Area] = @original_Area AND [Topic] = @original_Topic AND [Issue] = @original_Issue AND [Update] = @original_Update"
InsertCommand="INSERT INTO [TBL_FAQ1] ([FormInserted], [Area], [Topic], [Issue], [Update]) VALUES (@FormInserted, @Area, @Topic, @Issue, @Update)"
OldValuesParameterFormatString="original_{0}"
SelectCommand="SELECT [FAQ1ID], [FormInserted], [Area], [Topic], [Issue], [Update] FROM [TBL_FAQ1] WHERE ([Area] = @Area)"
UpdateCommand="UPDATE [TBL_FAQ1] SET [FormInserted] = @FormInserted, [Area] = @Area, [Topic] = @Topic, [Issue] = @Issue, [Update] = @Update WHERE [FAQ1ID] = @original_FAQ1ID AND [FormInserted] = @original_FormInserted AND [Area] = @original_Area AND [Topic] = @original_Topic AND [Issue] = @original_Issue AND [Update] = @original_Update">
<SelectParameters>
<asparameter DefaultValue="CXP" Name="Area" Type="String" />
</SelectParameters>
<DeleteParameters>
<asparameter Name="original_FAQ1ID" Type="Int32" />
<asparameter Name="original_FormInserted" Type="DateTime" />
<asparameter Name="original_Area" Type="String" />
<asparameter Name="original_Topic" Type="String" />
<asparameter Name="original_Issue" Type="String" />
<asparameter Name="original_Update" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asparameter Name="FormInserted" Type="DateTime" />
<asparameter Name="Area" Type="String" />
<asparameter Name="Topic" Type="String" />
<asparameter Name="Issue" Type="String" />
<asparameter Name="Update" Type="String" />
<asparameter Name="original_FAQ1ID" Type="Int32" />
<asparameter Name="original_FormInserted" Type="DateTime" />
<asparameter Name="original_Area" Type="String" />
<asparameter Name="original_Topic" Type="String" />
<asparameter Name="original_Issue" Type="String" />
<asparameter Name="original_Update" Type="String" />
</UpdateParameters>
<InsertParameters>
<asparameter Name="FormInserted" Type="DateTime" />
<asparameter Name="Area" Type="String" />
<asparameter Name="Topic" Type="String" />
<asparameter Name="Issue" Type="String" />
<asparameter Name="Update" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
Thanks in advance!