-cr-
asked on
Must declare variable.
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. DetailsVie wInsertedE ventArgs)
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(B yVal sender As Object, ByVal e As System.Web.UI.WebControls. DetailsVie wUpdatedEv entArgs)
GridView1.DataBind()
End Sub
Protected Sub DropDownList1_SelectedInde xChanged(B yVal sender As Object, ByVal e As EventArgs)
DetailsView1.ChangeMode(De tailsViewM ode.ReadOn ly)
End Sub
Protected Sub GridView1_SelectedIndexCha nged(ByVal sender As Object, ByVal e As EventArgs)
DetailsView1.ChangeMode(De tailsViewM ode.ReadOn ly)
End Sub
Protected Sub GridView1_PageIndexChanged (ByVal sender As Object, ByVal e As EventArgs)
DetailsView1.ChangeMode(De tailsViewM ode.ReadOn ly)
End Sub
Protected Sub GridView1_Sorted(ByVal sender As Object, ByVal e As System.EventArgs)
DetailsView1.ChangeMode(De tailsViewM ode.ReadOn ly)
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(ByV al 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.SelectedValu e
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="SqlDataSourc e2" AutoPostBack="true"
DataTextField="equipmentty pe" runat="server" OnSelectedIndexChanged="Dr opDownList 1_Selected IndexChang ed" />
<asp:SqlDataSource ID="SqlDataSource2" runat="server" SelectCommand="SELECT DISTINCT [equipmenttype] FROM [equipmenttype]"
ConnectionString="<%$ ConnectionStrings:BamAdmin Connection String %>" />
<br />
<br />
<table>
<tr>
<td valign="top">
<asp:GridView ID="GridView1" AllowSorting="True" AllowPaging="True" runat="server"
DataSourceID="SqlDataSourc e1" DataKeyNames="id"
AutoGenerateColumns="False " Width="500px" SelectedIndex="0" OnSelectedIndexChanged="Gr idView1_Se lectedInde xChanged" OnPageIndexChanged="GridVi ew1_PageIn dexChanged " OnRowDeleted="GridView1_Ro wDeleted" 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="equipmentt ype" />
<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:BamAdmin Connection String %>"
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="SelectedValu e"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</td>
<td valign="top">
<asp:DetailsView AutoGenerateRows="False" DataKeyNames="id" DataSourceID="SqlDataSourc e3"
HeaderText="Author Details" ID="DetailsView1" runat="server" Width="275px" OnItemUpdated="DetailsView 1_ItemUpda ted" OnItemInserted="DetailsVie w1_ItemIns erted" OnDataBound="DetailsView1_ DataBound" >
<Fields>
<asp:BoundField DataField="id" HeaderText="id" ReadOnly="True" SortExpression="id" />
<asp:BoundField DataField="equipmenttype" HeaderText="type" SortExpression="equipmentt ype" />
<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:BamAdmin Connection String %>"
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="SelectedValu e"
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>
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(
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(B
GridView1.DataBind()
End Sub
Protected Sub DropDownList1_SelectedInde
DetailsView1.ChangeMode(De
End Sub
Protected Sub GridView1_SelectedIndexCha
DetailsView1.ChangeMode(De
End Sub
Protected Sub GridView1_PageIndexChanged
DetailsView1.ChangeMode(De
End Sub
Protected Sub GridView1_Sorted(ByVal sender As Object, ByVal e As System.EventArgs)
DetailsView1.ChangeMode(De
End Sub
Protected Sub GridView1_RowDeleted(ByVal
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(ByV
If (DetailsView1.CurrentMode = DetailsViewMode.Insert) Then
Dim stateTextBox As TextBox = CType(DetailsView1.Rows(6)
stateTextBox.Text = DropDownList1.SelectedValu
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="SqlDataSourc
DataTextField="equipmentty
<asp:SqlDataSource ID="SqlDataSource2" runat="server" SelectCommand="SELECT DISTINCT [equipmenttype] FROM [equipmenttype]"
ConnectionString="<%$ ConnectionStrings:BamAdmin
<br />
<br />
<table>
<tr>
<td valign="top">
<asp:GridView ID="GridView1" AllowSorting="True" AllowPaging="True" runat="server"
DataSourceID="SqlDataSourc
AutoGenerateColumns="False
<Columns>
<asp:CommandField ShowSelectButton="true" ShowDeleteButton="true" />
<asp:BoundField DataField="id" HeaderText="id" ReadOnly="True" SortExpression="id" />
<asp:BoundField DataField="equipmenttype" HeaderText="type" SortExpression="equipmentt
<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:BamAdmin
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="SelectedValu
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</td>
<td valign="top">
<asp:DetailsView AutoGenerateRows="False" DataKeyNames="id" DataSourceID="SqlDataSourc
HeaderText="Author Details" ID="DetailsView1" runat="server" Width="275px" OnItemUpdated="DetailsView
<Fields>
<asp:BoundField DataField="id" HeaderText="id" ReadOnly="True" SortExpression="id" />
<asp:BoundField DataField="equipmenttype" HeaderText="type" SortExpression="equipmentt
<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:BamAdmin
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="SelectedValu
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>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
/\ Look at my post ;-)
ASKER
Damn. I thought i was going crazy. It was a late night and earlymorning...Thanks I will fix this typo.
did this work for you?
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