我对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 编辑模式下进行了所有设置。这个想法是,当您搜索记录并单击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>