我正在爲一個項目做同樣的事情。我使用這種類型的C#電網的連接到SQL Server和更新工作正常,(你只需要改變的綁定列值,用於更新的SQL命令和參數進行更新。
<body>
<form id="form1" runat="server">
<div style="height: 300px">
<asp:Button CssClass="btn btn-primary" ID="btn_back_to_admin" runat="server" Text="Back to Admin" OnClick="btn_back_to_admin_Click" />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="ID" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None" Height="260px" style="margin-bottom: 116px">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="Nombre" HeaderText="Nombre" SortExpression="Nombre" />
<asp:BoundField DataField="Precio" HeaderText="Precio" SortExpression="Precio" />
<asp:BoundField DataField="Codigo" HeaderText="Codigo" SortExpression="Codigo" />
<asp:BoundField DataField="Garantia" HeaderText="Garantia" SortExpression="Garantia" />
<asp:BoundField DataField="Marca" HeaderText="Marca" SortExpression="Marca" />
<asp:BoundField DataField="AspectosTecnicos" HeaderText="AspectosTecnicos" SortExpression="AspectosTecnicos" />
<asp:BoundField DataField="Fotografia1" HeaderText="Fotografia" SortExpression="Fotografia1" />
<asp:BoundField DataField="Descripcion" HeaderText="Descripcion" SortExpression="Descripcion" />
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ShoppingConnectionString %>" DeleteCommand="DELETE FROM [main_product] WHERE [P_ID] = @P_ID" InsertCommand="INSERT INTO [main_product] ([Product_name], [MRP], [Our_Prize], [Discount], [Brand], [Brand_image], [Type_of_product], [Imagepath1], [Imagepath2], [Imagepath3], [Imagepath4], [Detail], [stock], [new_arrival], [best_seller], [best_offer]) VALUES (@Product_name, @MRP, @Our_Prize, @Discount, @Brand, @Brand_image, @Type_of_product, @Imagepath1, @Imagepath2, @Imagepath3, @Imagepath4, @Detail, @stock, @new_arrival, @best_seller, @best_offer)" SelectCommand="SELECT * FROM [FO_Productos]" UpdateCommand=" Exec FOSP_ActualizarProducto @ID , @Nombre, @Descripcion , @Codigo , @Marca , @Precio , @Garantia , @AspectosTecnicos , @Fotografia1 , @Fotografia1 ">
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Product_name" Type="String" />
<asp:Parameter Name="MRP" Type="Int32" />
<asp:Parameter Name="Our_Prize" Type="Int32" />
<asp:Parameter Name="Discount" Type="Int32" />
<asp:Parameter Name="Brand" Type="String" />
<asp:Parameter Name="Brand_image" Type="String" />
<asp:Parameter Name="Type_of_product" Type="String" />
<asp:Parameter Name="Imagepath1" Type="String" />
<asp:Parameter Name="Imagepath2" Type="String" />
<asp:Parameter Name="Imagepath3" Type="String" />
<asp:Parameter Name="Imagepath4" Type="String" />
<asp:Parameter Name="Detail" Type="String" />
<asp:Parameter Name="stock" Type="Int32" />
<asp:Parameter Name="new_arrival" Type="Int32" />
<asp:Parameter Name="best_seller" Type="Int32" />
<asp:Parameter Name="best_offer" Type="Int32" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="Nombre" Type="String" />
<asp:Parameter Name="Precio" Type="Int32" />
<asp:Parameter Name="Codigo" Type="Int32" />
<asp:Parameter Name="Garantia" Type="Int32" />
<asp:Parameter Name="Marca" Type="String" />
<asp:Parameter Name="AspectosTecnicos" Type="String" />
<asp:Parameter Name="Fotografia1" Type="String" />
<asp:Parameter Name="Descripcion" Type="String" />
<asp:Parameter Name="Imagepath2" Type="String" />
<asp:Parameter Name="Imagepath3" Type="String" />
<asp:Parameter Name="Imagepath4" Type="String" />
<asp:Parameter Name="Detail" Type="String" />
<asp:Parameter Name="stock" Type="Int32" />
<asp:Parameter Name="new_arrival" Type="Int32" />
<asp:Parameter Name="best_seller" Type="Int32" />
<asp:Parameter Name="best_offer" Type="Int32" />
<asp:Parameter Name="P_ID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:Button ID="Button1" CssClass="btn btn-primary" runat="server" Text="Back To admin Console" OnClick="Button1_Click" />
</div>
</form>
</body>
什麼是你的EventStatus列的數據類型?UPDATE EventsEnglish SET EventStatus = Close'如果數據類型是varchar這會給出錯誤,你忘了'(單引號) – jayvee
它是nvarchar(MAX) – user3599431
看來這是我真正的問題!thnx – user3599431