Solved

Must declare variable.

Posted on 2006-06-14
5
680 Views
Last Modified: 2008-01-09
I am fairly new to ASP.Net. I am encountering an error:
Must declare the scalar variable "@equipmmenttype".

I am not sure where or how I need to declare this.
Any help would be great. Thanks in advance !!


CODE:

<%@ Page Language="VB" %>
<script runat="server">

    Protected Sub DetailsView1_ItemInserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertedEventArgs)
   
        If (Not e.Exception Is Nothing) Then

            ErrorMessageLabel.Text = "An error occured while entering this record.  Please verify you have entered data in the correct format."
            e.ExceptionHandled = True
        End If
        GridView1.DataBind()
    End Sub

    Protected Sub DetailsView1_ItemUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdatedEventArgs)
   
        GridView1.DataBind()
    End Sub

    Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
   
        DetailsView1.ChangeMode(DetailsViewMode.ReadOnly)
    End Sub

    Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
   
        DetailsView1.ChangeMode(DetailsViewMode.ReadOnly)
    End Sub

    Protected Sub GridView1_PageIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
   
        DetailsView1.ChangeMode(DetailsViewMode.ReadOnly)
    End Sub

    Protected Sub GridView1_Sorted(ByVal sender As Object, ByVal e As System.EventArgs)
        DetailsView1.ChangeMode(DetailsViewMode.ReadOnly)
    End Sub
   
    Protected Sub GridView1_RowDeleted(ByVal sender As Object, ByVal e As GridViewDeletedEventArgs)
   
        If (Not e.Exception Is Nothing) Then
       
            ErrorMessageLabel.Text = "Failed to DELETE due to foreign key contstraint on the table.  You may only delete rows which have no related records."
            e.ExceptionHandled = True
        End If
    End Sub

    Protected Sub DetailsView1_DataBound(ByVal sender As Object, ByVal e As EventArgs)
   
        If (DetailsView1.CurrentMode = DetailsViewMode.Insert) Then
       
            Dim stateTextBox As TextBox = CType(DetailsView1.Rows(6).Cells(1).Controls(0), TextBox)
            stateTextBox.Text = DropDownList1.SelectedValue
            stateTextBox.Enabled = False
        End If
    End Sub

</script>
<html>
<head id="Head1" runat="server">
  <title>GridView DetailsView Master-Details (Insert)</title>
</head>
<body>
  <form id="form1" runat="server">
    <b>Choose a state:</b>
    <asp:DropDownList ID="DropDownList1" DataSourceID="SqlDataSource2" AutoPostBack="true"
      DataTextField="equipmenttype" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" />
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" SelectCommand="SELECT DISTINCT [equipmenttype] FROM [equipmenttype]"
      ConnectionString="<%$ ConnectionStrings:BamAdminConnectionString %>" />
    <br />
    <br />
    <table>
      <tr>
        <td valign="top">
          <asp:GridView ID="GridView1" AllowSorting="True" AllowPaging="True" runat="server"
            DataSourceID="SqlDataSource1" DataKeyNames="id"
            AutoGenerateColumns="False" Width="500px" SelectedIndex="0" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnPageIndexChanged="GridView1_PageIndexChanged" OnRowDeleted="GridView1_RowDeleted" OnSorted="GridView1_Sorted">
            <Columns>
              <asp:CommandField ShowSelectButton="true" ShowDeleteButton="true" />
              <asp:BoundField DataField="id" HeaderText="id" ReadOnly="True" SortExpression="id" />
              <asp:BoundField DataField="equipmenttype" HeaderText="type" SortExpression="equipmenttype" />
              <asp:BoundField DataField="make" HeaderText="make" SortExpression="make" />
              <asp:BoundField DataField="model" HeaderText="model" SortExpression="model" />
              <asp:BoundField DataField="serial" HeaderText="serial" SortExpression="serial" />
              <asp:BoundField DataField="owner" HeaderText="owner" SortExpression="owner" />
              <asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
            </Columns>
          </asp:GridView>
          <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:BamAdminConnectionString %>"
            SelectCommand="SELECT [id], [equipmenttype], [make], [model], [serial], [owner], [name] FROM [hardwareinventory] WHERE ([equipmmenttype] = @equipmmenttype)"
            DeleteCommand="DELETE FROM [hardwareinventory] WHERE [id] = @id">
            <SelectParameters>
              <asp:ControlParameter ControlID="DropDownList1" Name="equipmenttype" PropertyName="SelectedValue"
                Type="String" />
            </SelectParameters>
          </asp:SqlDataSource>
        </td>
        <td valign="top">
          <asp:DetailsView AutoGenerateRows="False" DataKeyNames="id" DataSourceID="SqlDataSource3"
            HeaderText="Author Details" ID="DetailsView1" runat="server" Width="275px" OnItemUpdated="DetailsView1_ItemUpdated" OnItemInserted="DetailsView1_ItemInserted" OnDataBound="DetailsView1_DataBound">
            <Fields>
              <asp:BoundField DataField="id" HeaderText="id" ReadOnly="True" SortExpression="id" />
              <asp:BoundField DataField="equipmenttype" HeaderText="type" SortExpression="equipmenttype" />
              <asp:BoundField DataField="make" HeaderText="make" SortExpression="make" />
              <asp:BoundField DataField="model" HeaderText="model" SortExpression="model" />
              <asp:BoundField DataField="serial" HeaderText="address" SortExpression="serial" />
              <asp:BoundField DataField="owner" HeaderText="city" SortExpression="owner" />
              <asp:CommandField ShowEditButton="True" ShowInsertButton="True" />
            </Fields>
          </asp:DetailsView>
          <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:BamAdminConnectionString %>"
            SelectCommand="SELECT [id], [equipmenttype], [make], [model], [serial], [owner], [name] FROM [hardwareinventory] WHERE ([id] = @id)"
            UpdateCommand="UPDATE [hardwareinventory] SET [equipmenttype] = @equipmenttype, [make] = @make, [model] = @model, [serial] = @serial, [owner] = @owner, [name] = @name WHERE [id] = @id"
            InsertCommand="INSERT INTO [hardwareinventory] ([equipmenttype], [make], [model], [serial], [owner], [name]) VALUES (@equipmenttype, @make, @model, @serial, @owner, @name)">
            <SelectParameters>
              <asp:ControlParameter ControlID="GridView1" Name="id" PropertyName="SelectedValue"
                Type="String" />
            </SelectParameters>
            <UpdateParameters>
              <asp:Parameter Name="equipmenttype" Type="String" />
              <asp:Parameter Name="make" Type="String" />
              <asp:Parameter Name="model" Type="String" />
              <asp:Parameter Name="serial" Type="String" />
              <asp:Parameter Name="owner" Type="String" />
               <asp:Parameter Name="id" Type="String" />
            </UpdateParameters>
            <InsertParameters>
              <asp:Parameter Name="equipmenttype" Type="String" />
              <asp:Parameter Name="make" Type="String" />
              <asp:Parameter Name="model" Type="String" />
              <asp:Parameter Name="serial" Type="String" />
              <asp:Parameter Name="owner" Type="String" />
              <asp:Parameter Name="name" Type="String" />
            </InsertParameters>
          </asp:SqlDataSource>
        </td>
      </tr>
    </table>
    <br />
    <asp:Label ID="ErrorMessageLabel" EnableViewState="false" runat="server" />
  </form>
</body>
</html>
0
Comment
Question by:-cr-
  • 3
5 Comments
 
LVL 20

Accepted Solution

by:
REA_ANDREW earned 500 total points
ID: 16901703
I think it is just a small spelling error

@equipmmenttype

and then you define this parameter as

equipmenttype

notice the extra m in the first
0
 
LVL 7

Expert Comment

by:pradeepsudharsan
ID: 16901965
Hai  
you put 2 m's instead of single 'm'
error lines
SelectCommand="SELECT [id], [equipmenttype], [make], [model], [serial], [owner], [name] FROM [hardwareinventory] WHERE ([equipmmenttype] = @equipmmenttype)"

Regards

Pradeep
0
 
LVL 20

Expert Comment

by:REA_ANDREW
ID: 16901985
/\ Look at my post ;-)
0
 

Author Comment

by:-cr-
ID: 16902206
Damn. I thought i was going crazy. It was a late night and earlymorning...Thanks I will fix this typo.
0
 
LVL 20

Expert Comment

by:REA_ANDREW
ID: 16904209
did this work for you?
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question