Solved

Must declare variable.

Posted on 2006-06-14
5
678 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
Comment Utility
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
Comment Utility
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
Comment Utility
/\ Look at my post ;-)
0
 

Author Comment

by:-cr-
Comment Utility
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
Comment Utility
did this work for you?
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now