asp.net ช่วยตรวจสอบโค้ดไห้หน่อยครับว่าผิดตรงไหนลบข้อมูลจาก base Mysql ไม่ได้
Code (ASP)
<div style="height:500px">
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" BackColor="White" BorderColor="#CCCCCC"
BorderStyle="None" BorderWidth="1px" CellPadding="3" DataKeyNames="รหัสผู้ค้า"
DataSourceID="SqlDataSource1">
<Columns>
<asp:CommandField ButtonType="Button" CancelText="ยกเลิก" DeleteText="ลบ"
EditText="แก้ไข" InsertText="เพิ่ม" ShowDeleteButton="True"
ShowEditButton="True" ShowSelectButton="True" />
<asp:BoundField DataField="รหัสผู้ค้า" HeaderText="รหัสผู้ค้า"
InsertVisible="False" ReadOnly="True" SortExpression="รหัสผู้ค้า" />
<asp:BoundField DataField="ชื่อบริษัท" HeaderText="ชื่อบริษัท"
SortExpression="ชื่อบริษัท" />
<asp:BoundField DataField="รหัสบริษัท" HeaderText="รหัสบริษัท"
SortExpression="รหัสบริษัท" />
<asp:BoundField DataField="วันที่สั่งซื้อ" HeaderText="วันที่สั่งซื้อ"
SortExpression="วันที่สั่งซื้อ" />
<asp:BoundField DataField="รายละเอียดสินค้า" HeaderText="รายละเอียดสินค้า"
SortExpression="รายละเอียดสินค้า" />
<asp:BoundField DataField="จำนวน" HeaderText="จำนวน" SortExpression="จำนวน" />
<asp:BoundField DataField="ราคา" HeaderText="ราคา" SortExpression="ราคา" />
</Columns>
<EmptyDataTemplate>
ไม่มีข้อมูลข้อมูล
</EmptyDataTemplate>
<FooterStyle BackColor="White" ForeColor="#000066" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#007DBB" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#00547E" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:EcommerceConnectionString %>"
DeleteCommand="DELETE FROM [suply] WHERE [spid] = @original_spid AND (([compnayname] = @original_compnayname) OR ([compnayname] IS NULL AND @original_compnayname IS NULL)) AND (([companycode] = @original_companycode) OR ([companycode] IS NULL AND @original_companycode IS NULL)) AND (([orderdate] = @original_orderdate) OR ([orderdate] IS NULL AND @original_orderdate IS NULL)) AND (([orderdetail] = @original_orderdetail) OR ([orderdetail] IS NULL AND @original_orderdetail IS NULL)) AND (([orderamount] = @original_orderamount) OR ([orderamount] IS NULL AND @original_orderamount IS NULL)) AND (([orderprice] = @original_orderprice) OR ([orderprice] IS NULL AND @original_orderprice IS NULL))"
InsertCommand="INSERT INTO [suply] ([compnayname], [companycode], [orderdate], [orderdetail], [orderamount], [orderprice]) VALUES (@compnayname, @companycode, @orderdate, @orderdetail, @orderamount, @orderprice)"
OldValuesParameterFormatString="original_{0}"
SelectCommand="SELECT [spid]AS รหัสผู้ค้า, [compnayname] AS ชื่อบริษัท, [companycode] AS รหัสบริษัท, [orderdate] AS วันที่สั่งซื้อ, [orderdetail] AS รายละเอียดสินค้า, [orderamount] AS จำนวน, [orderprice] AS ราคา FROM [suply]"
UpdateCommand="UPDATE [suply] SET [compnayname] = @compnayname, [companycode] = @companycode, [orderdate] = @orderdate, [orderdetail] = @orderdetail, [orderamount] = @orderamount, [orderprice] = @orderprice WHERE [spid] = @original_spid AND (([compnayname] = @original_compnayname) OR ([compnayname] IS NULL AND @original_compnayname IS NULL)) AND (([companycode] = @original_companycode) OR ([companycode] IS NULL AND @original_companycode IS NULL)) AND (([orderdate] = @original_orderdate) OR ([orderdate] IS NULL AND @original_orderdate IS NULL)) AND (([orderdetail] = @original_orderdetail) OR ([orderdetail] IS NULL AND @original_orderdetail IS NULL)) AND (([orderamount] = @original_orderamount) OR ([orderamount] IS NULL AND @original_orderamount IS NULL)) AND (([orderprice] = @original_orderprice) OR ([orderprice] IS NULL AND @original_orderprice IS NULL))">
<DeleteParameters>
<asp:Parameter Name="original_spid" Type="Int32" />
<asp:Parameter Name="original_compnayname" Type="String" />
<asp:Parameter Name="original_companycode" Type="String" />
<asp:Parameter DbType="Date" Name="original_orderdate" />
<asp:Parameter Name="original_orderdetail" Type="String" />
<asp:Parameter Name="original_orderamount" Type="Int32" />
<asp:Parameter Name="original_orderprice" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="compnayname" Type="String" />
<asp:Parameter Name="companycode" Type="String" />
<asp:Parameter DbType="Date" Name="orderdate" />
<asp:Parameter Name="orderdetail" Type="String" />
<asp:Parameter Name="orderamount" Type="Int32" />
<asp:Parameter Name="orderprice" Type="Int32" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="compnayname" Type="String" />
<asp:Parameter Name="companycode" Type="String" />
<asp:Parameter DbType="Date" Name="orderdate" />
<asp:Parameter Name="orderdetail" Type="String" />
<asp:Parameter Name="orderamount" Type="Int32" />
<asp:Parameter Name="orderprice" Type="Int32" />
<asp:Parameter Name="original_spid" Type="Int32" />
<asp:Parameter Name="original_compnayname" Type="String" />
<asp:Parameter Name="original_companycode" Type="String" />
<asp:Parameter DbType="Date" Name="original_orderdate" />
<asp:Parameter Name="original_orderdetail" Type="String" />
<asp:Parameter Name="original_orderamount" Type="Int32" />
<asp:Parameter Name="original_orderprice" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl="~/ReportSuplyShow.aspx" Target="_blank">พิมพ์รายงานการสั่งซื้อ</asp:HyperLink>
</div>
<div>
<asp:FormView ID="FormView1" runat="server" DataKeyNames="spid"
DataSourceID="SqlDataSource2" DefaultMode="Insert">
<EditItemTemplate>
spid:
<asp:Label ID="spidLabel1" runat="server" Text='<%# Eval("spid") %>' />
<br />
companycode:
<asp:TextBox ID="companycodeTextBox" runat="server"
Text='<%# Bind("companycode") %>' />
<br />
compnayname:
<asp:TextBox ID="compnaynameTextBox" runat="server"
Text='<%# Bind("compnayname") %>' />
<br />
orderdate:
<asp:TextBox ID="orderdateTextBox" runat="server"
Text='<%# Bind("orderdate") %>' />
<br />
orderdetail:
<asp:TextBox ID="orderdetailTextBox" runat="server"
Text='<%# Bind("orderdetail") %>' />
<br />
orderamount:
<asp:TextBox ID="orderamountTextBox" runat="server"
Text='<%# Bind("orderamount") %>' />
<br />
orderprice:
<asp:TextBox ID="orderpriceTextBox" runat="server"
Text='<%# Bind("orderprice") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"
CommandName="Update" Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<InsertItemTemplate>
รหัสบริษัท:
<asp:TextBox ID="companycodeTextBox" runat="server"
Text='<%# Bind("companycode") %>' />
<br />
ชื่อบริษัท:
<asp:TextBox ID="compnaynameTextBox" runat="server"
Text='<%# Bind("compnayname") %>' />
<br />
วันที่สั่งซื้อ:
<asp:TextBox ID="orderdateTextBox" runat="server"
Text='<%# Bind("orderdate") %>' />
2012/2/29<br />รายละเอียด:
<asp:TextBox ID="orderdetailTextBox" runat="server"
Text='<%# Bind("orderdetail") %>' />
<br />
จำนวน:
<asp:TextBox ID="orderamountTextBox" runat="server"
Text='<%# Bind("orderamount") %>' />
<br />
ราคา:
<asp:TextBox ID="orderpriceTextBox" runat="server"
Text='<%# Bind("orderprice") %>' />
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="Insert" />
<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
spid:
<asp:Label ID="spidLabel" runat="server" Text='<%# Eval("spid") %>' />
<br />
companycode:
<asp:Label ID="companycodeLabel" runat="server"
Text='<%# Bind("companycode") %>' />
<br />
compnayname:
<asp:Label ID="compnaynameLabel" runat="server"
Text='<%# Bind("compnayname") %>' />
<br />
orderdate:
<asp:Label ID="orderdateLabel" runat="server" Text='<%# Bind("orderdate") %>' />
<br />
orderdetail:
<asp:Label ID="orderdetailLabel" runat="server"
Text='<%# Bind("orderdetail") %>' />
<br />
orderamount:
<asp:Label ID="orderamountLabel" runat="server"
Text='<%# Bind("orderamount") %>' />
<br />
orderprice:
<asp:Label ID="orderpriceLabel" runat="server"
Text='<%# Bind("orderprice") %>' />
<br />
<asp:LinkButton ID="EditButton" runat="server" CausesValidation="False"
CommandName="Edit" Text="Edit" />
<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False"
CommandName="Delete" Text="Delete" />
<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False"
CommandName="New" Text="New" />
</ItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:EcommerceConnectionString %>"
DeleteCommand="DELETE FROM [suply] WHERE [spid] = @spid"
InsertCommand="INSERT INTO [suply] ([companycode], [compnayname], [orderdate], [orderdetail], [orderamount], [orderprice]) VALUES (@companycode, @compnayname, @orderdate, @orderdetail, @orderamount, @orderprice)"
SelectCommand="SELECT * FROM [suply]"
UpdateCommand="UPDATE [suply] SET [companycode] = @companycode, [compnayname] = @compnayname, [orderdate] = @orderdate, [orderdetail] = @orderdetail, [orderamount] = @orderamount, [orderprice] = @orderprice WHERE [spid] = @spid">
<DeleteParameters>
<asp:Parameter Name="spid" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="companycode" Type="String" />
<asp:Parameter Name="compnayname" Type="String" />
<asp:Parameter DbType="Date" Name="orderdate" />
<asp:Parameter Name="orderdetail" Type="String" />
<asp:Parameter Name="orderamount" Type="Int32" />
<asp:Parameter Name="orderprice" Type="Int32" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="companycode" Type="String" />
<asp:Parameter Name="compnayname" Type="String" />
<asp:Parameter DbType="Date" Name="orderdate" />
<asp:Parameter Name="orderdetail" Type="String" />
<asp:Parameter Name="orderamount" Type="Int32" />
<asp:Parameter Name="orderprice" Type="Int32" />
<asp:Parameter Name="spid" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
</div>
<br />
<br />
มันลบข้อมูลจากเบสไม่ได้อ่ะครับ error ก็ไม่ฟ้องTag : ASP.NET, Web (ASP.NET)
Date :
2012-03-02 02:57:25
By :
kahapol
View :
1183
Reply :
1
เขียนแบบนี้หาและ Debug ยากครับ ทำไมไม่ลองเขียน code เองครับ ไม่ยากเลย
Code (VB.NET)
IF e.CommandName = "Delete" Then
'*** CustomerID ***'
Dim lblCustomerID As Label = CType(e.Item.FindControl("lblCustomerID"),Label)
strSQL = "DELETE FROM customer WHERE CustomerID = '"& lblCustomerID.Text &"' "
objCmd = New MySqlCommand(strSQL, objConn)
objCmd.ExecuteNonQuery()
BindData()
End IF
Go to : ASP.NET MySQL Delete Record
Date :
2012-03-02 05:59:07
By :
webmaster
Load balance : Server 04