Solved

Must declare variable.

Posted on 2006-06-14
5
683 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-
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

688 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