473,387 Members | 3,801 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

sqldatasource and gridview problem

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>

Aug 29 '06 #1
1 2583
figured it out, I needed the datakeynames parameter set in my gridview
creation.

"nate" wrote:
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>
Aug 29 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Mike Kelly | last post by:
I've chosen to implement the "optimistic concurrency" model in my application. To assist in that, I've added a ROWVERSION (TIMESTAMP) column to my main tables. I read the value of the column in my...
3
by: adam222 | last post by:
hello, i have a web-form with a GridView control, i wanted to update & delete, using the AutoGenerateEditButton. when i used it with sqlDataSource (executing SP in the DB) it works like a...
3
by: simonZ | last post by:
In gridView I have dropdown list : <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ProductID" DataSourceID="SqlDataSource1"> <Columns> <asp:BoundField...
0
by: Giovanni | last post by:
I was wondering if someone would be able to help me with the following: Simply put, I have built an ASP.NET 2.0 WebUserControl (UC1). UC1 contains: A GridView which is bound to an SQLDataSource...
1
by: Mike P | last post by:
When you use a SqlDataSource to hook up data to a GridView it seems to be to be very inflexible. For example, I want to create my own Delete button with my own code and I also want to create a...
0
by: jobs | last post by:
I have a gridview that times when selecting from specific table when I try to when I add a where clause. Even when I'm only seleting Top 1 which comes right back at the command line. I test the...
0
by: LiamLiamLiam | last post by:
G'day all. I having a problem with my formview. I'll ty to explain my situation as best as i can. I have a page with a search field at the top which is just a simple asp:textbox. Below that i...
1
by: sheenaa | last post by:
Hello Members, I m creating my application forms in ASP.Net 2005 C# using the backend SQL Server 2005. What i have used on forms :: ? On my first form i have used some...
4
by: mohaaron | last post by:
This seems like it should be simple to do but for some reason I have been unable to make it work. I would like to databind a SqlDataSource to a GridView during the click event of a button. This...
1
by: ken | last post by:
Hi All, I try to using the dotnet control instead of code behind to create a quick solution (ASP.NET with VB.NET) by using the SqlDataSource and GridView control (with SelectCommand,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.