さて、私はゆっくりとプロジェクトを進めていますが、次のエラーメッセージを受け取ります。
「ParameterName'Name'のSqlParameterは、このSqlParameterCollectionに含まれていません。」
エラーは、私のvbコードの次のステートメントを示しています:e.Command.Parameters( "Name")。Value = NewName.Text
誰かが私のコードを見て、私が間違っているかもしれないことを手伝ってくれませんか。
これが私のvbコードです:
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Private Sub GridView1_RowCommand(sender As Object, e As GridViewCommandEventArgs) Handles Laboratory.RowCommand
' Insert data if the CommandName == "Insert"
' and the validation controls indicate valid data...
If e.CommandName = "Insert" AndAlso Page.IsValid Then
' Insert new record...
SqlDataSource2.Insert()
End If
End Sub
Protected Sub SqlDataSource2_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles SqlDataSource2.Inserting
' Programmatically reference Web controls in the inserting interface...
Dim NewName As TextBox = Laboratory.FooterRow.FindControl("txtName")
Dim NewAddress As TextBox = Laboratory.FooterRow.FindControl("txtAddress")
Dim NewProvidence As TextBox = Laboratory.FooterRow.FindControl("txtProvidence")
Dim NewCity As TextBox = Laboratory.FooterRow.FindControl("txtCity")
Dim NewZipCode As TextBox = Laboratory.FooterRow.FindControl("txtZipCode")
Dim NewCountry As TextBox = Laboratory.FooterRow.FindControl("txtcountry")
Dim NewPhone As TextBox = Laboratory.FooterRow.FindControl("txtPhone")
Dim NewFax As TextBox = Laboratory.FooterRow.FindControl("txtFax")
Dim NewEmail As TextBox = Laboratory.FooterRow.FindControl("txtEmail")
' Set the ObjectDataSource's InsertParameters values...
' THIS IS WHERE I THINK I AM HAVING MY PROBLEM...
e.Command.Parameters("Name").Value = NewName.Text
e.Command.Parameters("Address").Value = NewAddress.Text
e.Command.Parameters("Providence").Value = NewProvidence.Text
e.Command.Parameters("City").Value = NewCity.Text
e.Command.Parameters("ZipCode").Value = NewZipCode.Text
e.Command.Parameters("Country").Value = NewCountry.Text
e.Command.Parameters("Phone").Value = NewPhone.Text
e.Command.Parameters("Fax").Value = NewFax.Text
e.Command.Parameters("Email").Value = NewEmail.Text
End Sub
そして、これが私のhtmlです。
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<br />
<br />
<br />
<br />
<asp:GridView ID="Laboratory" runat="server" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="LaboratoryID" DataSourceID="SqlDataSource2" ShowFooter="True">
<Columns>
<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update" Text="Update"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"></asp:LinkButton>
</EditItemTemplate>
<FooterTemplate>
<asp:Button ID="AddRow" runat="server" CommandName="Insert" Text="Add" />
</FooterTemplate>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name" SortExpression="Name">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="TxtName" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Address" SortExpression="Address">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Address") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtAddress" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Address") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Providence" SortExpression="Providence">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Providence") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="TxtProvidence" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("Providence") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="City" SortExpression="City">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("City") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="TxtCity" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("City") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ZipCode" SortExpression="ZipCode">
<EditItemTemplate>
<asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("ZipCode") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="TxtZipCode" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("ZipCode") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Country" SortExpression="Country">
<EditItemTemplate>
<asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("Country") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="TxtCountry" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("Country") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Phone" SortExpression="Phone">
<EditItemTemplate>
<asp:TextBox ID="TextBox7" runat="server" Text='<%# Bind("Phone") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="TxtPhone" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Bind("Phone") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Fax" SortExpression="Fax">
<EditItemTemplate>
<asp:TextBox ID="TextBox8" runat="server" Text='<%# Bind("Fax") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="TxtFax" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label8" runat="server" Text='<%# Bind("Fax") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Email" SortExpression="Email">
<EditItemTemplate>
<asp:TextBox ID="TextBox9" runat="server" Text='<%# Bind("Email") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="TxtEmail" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label9" runat="server" Text='<%# Bind("Email") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:GreatGrizzlyConnectionString1 %>" DeleteCommand="DELETE FROM [Laboratory] WHERE [LaboratoryID] = @LaboratoryID" InsertCommand="INSERT INTO [Laboratory] ([Name], [Address], [Providence], [City], [ZipCode], [Country], [Phone], [Fax], [Email]) VALUES (@Name, @Address, @Providence, @City, @ZipCode, @Country, @Phone, @Fax, @Email)" SelectCommand="SELECT * FROM [Laboratory]" UpdateCommand="UPDATE [Laboratory] SET [Name] = @Name, [Address] = @Address, [Providence] = @Providence, [City] = @City, [ZipCode] = @ZipCode, [Country] = @Country, [Phone] = @Phone, [Fax] = @Fax, [Email] = @Email WHERE [LaboratoryID] = @LaboratoryID">
<DeleteParameters>
<asp:Parameter Name="LaboratoryID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Address" Type="String" />
<asp:Parameter Name="Providence" Type="String" />
<asp:Parameter Name="City" Type="String" />
<asp:Parameter Name="ZipCode" Type="String" />
<asp:Parameter Name="Country" Type="String" />
<asp:Parameter Name="Phone" Type="String" />
<asp:Parameter Name="Fax" Type="String" />
<asp:Parameter Name="Email" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Address" Type="String" />
<asp:Parameter Name="Providence" Type="String" />
<asp:Parameter Name="City" Type="String" />
<asp:Parameter Name="ZipCode" Type="String" />
<asp:Parameter Name="Country" Type="String" />
<asp:Parameter Name="Phone" Type="String" />
<asp:Parameter Name="Fax" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="LaboratoryID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<br />
<br />
<br />
<br />
<br />
<br />
</div>
</form>
</body>
</html>