Newbie, gridview problem Asp.net 2005

Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

    Default Newbie, gridview problem Asp.net 2005

    Hi
    Can anyone help me I'm running Win XP Pro SP2, VS2005 Team, .Net Framework
    2.0 and SQL Server2005, I can't delete records using the gridviews
    deletecommand, the updatecommand works fine, edit and calcel all works fine
    the problem is the delete part, I get the message:

    -----------------------------------------------ERROR
    MESSAGE----------------------------------------------------------------------------------------
    Must declare the scalar variable "@productid".
    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
    scalar variable "@productid".
    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


    Here's my default3.aspx source code so far I've been stuck two days, thanks
    and best regards. :(

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default3.aspx.vb"
    Inherits="Default3" %>
    !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:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
    ConnectionStrings:NwindConnectionString %>"

    SelectCommand="SELECT p.ProductID, p.ProductName, p.CategoryID,
    c.CategoryName FROM Products p inner join Categories c on p.CategoryID =
    c.CategoryID"

    UpdateCommand="Update Products Set ProductID=@ProductID,
    ProductName=@ProductName, CategoryID=@CategoryID where ProductID=@ProductID"

    DeleteCommand="delete from products where productid=@productid">

    </asp:SqlDataSource>

    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$
    ConnectionStrings:NwindConnectionString %>"

    SelectCommand="SELECT [CategoryID], [CategoryName] FROM [Categories]">

    </asp:SqlDataSource>

    </div>

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
    DataSourceID="SqlDataSource1" CellPadding="4" ForeColor="#333333"
    GridLines="None" AllowPaging="True">

    <Columns>

    <asp:CommandField ButtonType="Image" CancelImageUrl="~/Images/Cancel.gif"
    EditImageUrl="~/Images/WRITE2.gif"

    ShowEditButton="True" UpdateImageUrl="~/Images/Update.gif"
    DeleteImageUrl="~/Images/waste-trash.gif" ShowDeleteButton="True" />

    <asp:TemplateField SortExpression="ProductID">

    <EditItemTemplate>

    <asp:Label ID="TextBox1" runat="server" Text='<%# Bind("ProductID")%>'
    Visible=false></asp:Label>

    </EditItemTemplate>

    <ItemTemplate>

    <asp:Label ID="Label2" runat="server" Text='<%# Bind("ProductID") %>'
    Visible=false></asp:Label>

    </ItemTemplate>

    </asp:TemplateField>

    <asp:BoundField DataField="ProductName" HeaderText="ProductName"
    SortExpression="ProductName" />

    <asp:TemplateField HeaderText="CategoryID" SortExpression="CategoryID">

    <EditItemTemplate>

    <asp:DropDownList ID="DropDownList1" runat="server"
    DataSourceID="SqlDataSource2"

    DataTextField="CategoryName" DataValueField="CategoryID" SelectedValue='<%#
    Bind("CategoryID") %>' >

    </asp:DropDownList>

    </EditItemTemplate>

    <ItemTemplate>

    <asp:Label ID="Label1" runat="server" Text='<%# Bind("CategoryName")
    %>'></asp:Label>

    </ItemTemplate>

    </asp:TemplateField>

    </Columns>

    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />

    <SelectedRowStyle BackColor="#D1DDF1" ForeColor="#333333" Font-Bold="True"
    />

    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center"
    />

    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />

    <AlternatingRowStyle BackColor="White" />

    <RowStyle BackColor="#EFF3FB" />

    <EditRowStyle BackColor="#2461BF" />

    </asp:GridView>

    </form>

    </body>

    </html>


    verci Guest

  2. Similar Questions and Discussions

    1. Newbie, how to check if a value in a gridview cell already exist in database
      Hi I've the following dataset bound to my gridview <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$...
    2. Newbie, how to validate data in cells in a gridview
      Hi, sorry if this seems stupid. :( How can I validate the values in each cell after editing and the update button/link has been press?, is this...
    3. Newbie, add a button to gridview footer
      Hi Can anyone help me or point me in the right direction, I'm running Win XP Pro SP2, VS2005 Team, .Net Framework 2.0 and SQL Server2005. I...
    4. Newbie, adding a row to Gridview in VB
      Hi Can anyone help me or point me in the right direction, I'm running Win XP Pro SP2, VS2005 Team, .Net Framework 2.0 and SQL Server2005. I...
    5. Refreshing gridview problem
      Hi, I have a form that inserts data into a table and a gridview to display the inserted values after insertion. here is the problem. the gridview...
  3. #2

    Default RE: Newbie, gridview problem Asp.net 2005

    Sorry for making you wait,
    Just add the property DataKeyNames="ProductID" to you grid view
    This would work for you inshallah
    Regards
    --
    Muhammad Mosa
    Software Engineer & Solution Developer
    MCT/MCSD.NET
    MCTS: .Net 2.0 Web Applications
    MCTS: .Net 2.0 Windows Applications


    "verci" wrote:
    > Hi
    > Can anyone help me I'm running Win XP Pro SP2, VS2005 Team, .Net Framework
    > 2.0 and SQL Server2005, I can't delete records using the gridviews
    > deletecommand, the updatecommand works fine, edit and calcel all works fine
    > the problem is the delete part, I get the message:
    >
    > -----------------------------------------------ERROR
    > MESSAGE----------------------------------------------------------------------------------------
    > Must declare the scalar variable "@productid".
    > 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
    > scalar variable "@productid".
    > -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    >
    >
    > Here's my default3.aspx source code so far I've been stuck two days, thanks
    > and best regards. :(
    >
    > <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default3.aspx.vb"
    > Inherits="Default3" %>
    > !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:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
    > ConnectionStrings:NwindConnectionString %>"
    >
    > SelectCommand="SELECT p.ProductID, p.ProductName, p.CategoryID,
    > c.CategoryName FROM Products p inner join Categories c on p.CategoryID =
    > c.CategoryID"
    >
    > UpdateCommand="Update Products Set ProductID=@ProductID,
    > ProductName=@ProductName, CategoryID=@CategoryID where ProductID=@ProductID"
    >
    > DeleteCommand="delete from products where productid=@productid">
    >
    > </asp:SqlDataSource>
    >
    > <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$
    > ConnectionStrings:NwindConnectionString %>"
    >
    > SelectCommand="SELECT [CategoryID], [CategoryName] FROM [Categories]">
    >
    > </asp:SqlDataSource>
    >
    > </div>
    >
    > <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
    > DataSourceID="SqlDataSource1" CellPadding="4" ForeColor="#333333"
    > GridLines="None" AllowPaging="True">
    >
    > <Columns>
    >
    > <asp:CommandField ButtonType="Image" CancelImageUrl="~/Images/Cancel.gif"
    > EditImageUrl="~/Images/WRITE2.gif"
    >
    > ShowEditButton="True" UpdateImageUrl="~/Images/Update.gif"
    > DeleteImageUrl="~/Images/waste-trash.gif" ShowDeleteButton="True" />
    >
    > <asp:TemplateField SortExpression="ProductID">
    >
    > <EditItemTemplate>
    >
    > <asp:Label ID="TextBox1" runat="server" Text='<%# Bind("ProductID")%>'
    > Visible=false></asp:Label>
    >
    > </EditItemTemplate>
    >
    > <ItemTemplate>
    >
    > <asp:Label ID="Label2" runat="server" Text='<%# Bind("ProductID") %>'
    > Visible=false></asp:Label>
    >
    > </ItemTemplate>
    >
    > </asp:TemplateField>
    >
    > <asp:BoundField DataField="ProductName" HeaderText="ProductName"
    > SortExpression="ProductName" />
    >
    > <asp:TemplateField HeaderText="CategoryID" SortExpression="CategoryID">
    >
    > <EditItemTemplate>
    >
    > <asp:DropDownList ID="DropDownList1" runat="server"
    > DataSourceID="SqlDataSource2"
    >
    > DataTextField="CategoryName" DataValueField="CategoryID" SelectedValue='<%#
    > Bind("CategoryID") %>' >
    >
    > </asp:DropDownList>
    >
    > </EditItemTemplate>
    >
    > <ItemTemplate>
    >
    > <asp:Label ID="Label1" runat="server" Text='<%# Bind("CategoryName")
    > %>'></asp:Label>
    >
    > </ItemTemplate>
    >
    > </asp:TemplateField>
    >
    > </Columns>
    >
    > <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    >
    > <SelectedRowStyle BackColor="#D1DDF1" ForeColor="#333333" Font-Bold="True"
    > />
    >
    > <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center"
    > />
    >
    > <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    >
    > <AlternatingRowStyle BackColor="White" />
    >
    > <RowStyle BackColor="#EFF3FB" />
    >
    > <EditRowStyle BackColor="#2461BF" />
    >
    > </asp:GridView>
    >
    > </form>
    >
    > </body>
    >
    > </html>
    >
    >
    >
    Muhammad Mosa Guest

  4. #3

    Default Re: Newbie, gridview problem Asp.net 2005

    hey thanks!!!


    "Muhammad Mosa" <MuhammadMosa@discussions.microsoft.com> w
    rote in message news:E0CB9859-F0EF-4BF3-9852-3E816193D3E2@microsoft.com...
    > Sorry for making you wait,
    > Just add the property DataKeyNames="ProductID" to you grid view
    > This would work for you inshallah
    > Regards
    > --
    > Muhammad Mosa
    > Software Engineer & Solution Developer
    > MCT/MCSD.NET
    > MCTS: .Net 2.0 Web Applications
    > MCTS: .Net 2.0 Windows Applications
    >
    >
    > "verci" wrote:
    >
    >> Hi
    >> Can anyone help me I'm running Win XP Pro SP2, VS2005 Team, .Net
    >> Framework
    >> 2.0 and SQL Server2005, I can't delete records using the gridviews
    >> deletecommand, the updatecommand works fine, edit and calcel all works
    >> fine
    >> the problem is the delete part, I get the message:
    >>
    >> -----------------------------------------------ERROR
    >> MESSAGE----------------------------------------------------------------------------------------
    >> Must declare the scalar variable "@productid".
    >> 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
    >> scalar variable "@productid".
    >> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    >>
    >>
    >> Here's my default3.aspx source code so far I've been stuck two days,
    >> thanks
    >> and best regards. :(
    >>
    >> <%@ Page Language="VB" AutoEventWireup="false"
    >> CodeFile="Default3.aspx.vb"
    >> Inherits="Default3" %>
    >> !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:SqlDataSource ID="SqlDataSource1" runat="server"
    >> ConnectionString="<%$
    >> ConnectionStrings:NwindConnectionString %>"
    >>
    >> SelectCommand="SELECT p.ProductID, p.ProductName, p.CategoryID,
    >> c.CategoryName FROM Products p inner join Categories c on p.CategoryID =
    >> c.CategoryID"
    >>
    >> UpdateCommand="Update Products Set ProductID=@ProductID,
    >> ProductName=@ProductName, CategoryID=@CategoryID where
    >> ProductID=@ProductID"
    >>
    >> DeleteCommand="delete from products where productid=@productid">
    >>
    >> </asp:SqlDataSource>
    >>
    >> <asp:SqlDataSource ID="SqlDataSource2" runat="server"
    >> ConnectionString="<%$
    >> ConnectionStrings:NwindConnectionString %>"
    >>
    >> SelectCommand="SELECT [CategoryID], [CategoryName] FROM [Categories]">
    >>
    >> </asp:SqlDataSource>
    >>
    >> </div>
    >>
    >> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
    >> DataSourceID="SqlDataSource1" CellPadding="4" ForeColor="#333333"
    >> GridLines="None" AllowPaging="True">
    >>
    >> <Columns>
    >>
    >> <asp:CommandField ButtonType="Image" CancelImageUrl="~/Images/Cancel.gif"
    >> EditImageUrl="~/Images/WRITE2.gif"
    >>
    >> ShowEditButton="True" UpdateImageUrl="~/Images/Update.gif"
    >> DeleteImageUrl="~/Images/waste-trash.gif" ShowDeleteButton="True" />
    >>
    >> <asp:TemplateField SortExpression="ProductID">
    >>
    >> <EditItemTemplate>
    >>
    >> <asp:Label ID="TextBox1" runat="server" Text='<%# Bind("ProductID")%>'
    >> Visible=false></asp:Label>
    >>
    >> </EditItemTemplate>
    >>
    >> <ItemTemplate>
    >>
    >> <asp:Label ID="Label2" runat="server" Text='<%# Bind("ProductID") %>'
    >> Visible=false></asp:Label>
    >>
    >> </ItemTemplate>
    >>
    >> </asp:TemplateField>
    >>
    >> <asp:BoundField DataField="ProductName" HeaderText="ProductName"
    >> SortExpression="ProductName" />
    >>
    >> <asp:TemplateField HeaderText="CategoryID" SortExpression="CategoryID">
    >>
    >> <EditItemTemplate>
    >>
    >> <asp:DropDownList ID="DropDownList1" runat="server"
    >> DataSourceID="SqlDataSource2"
    >>
    >> DataTextField="CategoryName" DataValueField="CategoryID"
    >> SelectedValue='<%#
    >> Bind("CategoryID") %>' >
    >>
    >> </asp:DropDownList>
    >>
    >> </EditItemTemplate>
    >>
    >> <ItemTemplate>
    >>
    >> <asp:Label ID="Label1" runat="server" Text='<%# Bind("CategoryName")
    >> %>'></asp:Label>
    >>
    >> </ItemTemplate>
    >>
    >> </asp:TemplateField>
    >>
    >> </Columns>
    >>
    >> <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    >>
    >> <SelectedRowStyle BackColor="#D1DDF1" ForeColor="#333333"
    >> Font-Bold="True"
    >> />
    >>
    >> <PagerStyle BackColor="#2461BF" ForeColor="White"
    >> HorizontalAlign="Center"
    >> />
    >>
    >> <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    >>
    >> <AlternatingRowStyle BackColor="White" />
    >>
    >> <RowStyle BackColor="#EFF3FB" />
    >>
    >> <EditRowStyle BackColor="#2461BF" />
    >>
    >> </asp:GridView>
    >>
    >> </form>
    >>
    >> </body>
    >>
    >> </html>
    >>
    >>
    >>

    verci Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139