sqldatasource and gridview problem

G

Guest

I am getting this error.
System.Data.SqlClient.SqlException: Must declare the variable '@InventoryID'.

At first I left the parameter declaration in the aspx page and then I tried
moving it to the codebehind as well. Still errored.

Codebehind snip----------------

public partial class Admin_AdminCreateInventory : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
MembershipUser user = Membership.GetUser();
SqlDataSource1.SelectCommand = "SELECT [InventoryID],
[InventoryName], [creationDate] FROM [InventoryList] WHERE ([owner] = '" +
user.ProviderUserKey.ToString() + "')";
SqlDataSource1.DeleteParameters.Add("InventoryID",
TypeCode.Int32, "");
SqlDataSource1.DeleteCommand = "DELETE FROM [InventoryList]
WHERE [InventoryID] = @InventoryID";
}
}

aspx snip----------------------
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master"
AutoEventWireup="true" CodeFile="AdminCreateInventory.aspx.cs"
Inherits="Admin_AdminCreateInventory" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<br />
Your current inventory Databases:<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:BaseConnectionString
%>"></asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" DataSourceID="SqlDataSource1">
<Columns>
<asp:CommandField ShowDeleteButton="True" />
</Columns>
</asp:GridView>
</asp:Content>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top