私はasp.netにかなり慣れていません。この更新SQLステートメントを作成しました:
Dim dbconn As SqlConnection
Dim dbcomm As SqlCommand
dbconn = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("sqlString"))
dbconn.Open()
Dim updateCmd As String = "UPDATE tbl_Project SET ID = @ID," _
& " Titel = @Titel, CatID = @CatID, Website = @Website," _
& " Naslag = @Naslag; WHERE ID = @ID;"
dbcomm = New SqlCommand(updateCmd, _
dbconn)
dbcomm.Parameters.Add(New SqlParameter("@ID", SqlDbType.Int))
dbcomm.Parameters.Add(New SqlParameter("@Titel", _
SqlDbType.VarChar))
dbcomm.Parameters.Add(New SqlParameter("@CatID", _
SqlDbType.Int))
dbcomm.Parameters.Add(New SqlParameter("@Website", _
SqlDbType.VarChar))
dbcomm.Parameters.Add(New SqlParameter("@Naslag", _
SqlDbType.VarChar))
dbcomm = New SqlCommand(updateCmd, dbconn)
dbcomm.ExecuteNonQuery()`
これをすべて Forview Edit モードでセットアップしました。アイデアは、レコードを検索してクリックするdetails
と、編集可能なプロジェクト ビューに移動するということです。詳細ページから編集し、プロジェクトを更新できます。
問題
[更新] ボタンをクリックすると、次のように表示されます: 私が持っている変数 @ID を宣言してください。そして、私は自分が間違っていることについての手がかりがありません。
ここに私のフォームビューがあります:
<table class="style1">
<tr>
<td class="style2">
<asp:Label ID="Label1" runat="server" CssClass="kopje" Text="Categorie"></asp:Label>
</td>
<td class="style3">
<asp:Label ID="Label2" runat="server" CssClass="kopje" Text="Klant"> </asp:Label>
</td>
<td class="style4">
<asp:Label ID="Label3" runat="server" CssClass="kopje " Text="Website"></asp:Label>
</td>
<td>
<asp:Label ID="Label5" runat="server" CssClass="kopje" Text="Titel"> </asp:Label>
</td>
</tr>
<tr>
<td class="style2">
<asp:DropDownList ID="DropDownCat" runat="server"
DataSourceID="SqlDataSourceDrop" DataTextField="Categorie"
DataValueField="Cat_ID" value="0">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSourceDrop" runat="server"
ConnectionString="<%$ ConnectionStrings:Goed %>"
SelectCommand="SELECT * FROM [tbl_Cat]">
<SelectParameters>
<asp:QueryStringParameter Name="ID" QueryStringField="ID" Type="Decimal" />
</SelectParameters>
</asp:SqlDataSource>
</td>
<td class="style3">
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSourceKlant" DataTextField="Bedrijf"
DataValueField="Klant_ID">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSourceKlant" runat="server"
ConnectionString="<%$ ConnectionStrings:Goed %>"
SelectCommand="SELECT * FROM [tbl_Klant]"></asp:SqlDataSource>
</td>
<td class="style4">
<asp:TextBox ID="TextBoxWebsite" runat="server" Text='<%# Eval("Website") %>'></asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBoxTitel" runat="server" Text='<%# Eval("Titel") %>'></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
<asp:Label ID="TextBoxOmschrijving" runat="server" CssClass="kopje"
Text="Omschrijving"></asp:Label>
</td>
<td class="style3">
</td>
<td class="style4">
</td>
<td>
</td>
</tr>
<tr>
<td class="style2">
<asp:TextBox ID="TextBoxslag" runat="server" Height="200px"
Text='<%# Eval("Naslag") %>' TextMode="MultiLine" Width="350px"></asp:TextBox>
</td>
<td class="style3">
</td>
<td class="style4">
</td>
<td>
</td>
</tr>
<tr>
<td class="style2">
<asp:LinkButton ID="LinkButton1" runat="server"
CausesValidation="True"
CssClass="buttons" Text="Update"
OnClientClick="Verzend"></asp:LinkButton>
</td>
<td class="style3">
</td>
<td class="style4">
</td>
<td>
</td>
</tr>
</table>
</EditItemTemplate>
</asp:FormView>