DELETE problem MySQL
Posted by: kevin perez
Date: January 22, 2008 01:16PM

Hi all,
I triying to INSERT, DELETE and UPDATE data using ASP.net So far I am be able to connect to mySQL database, display data, insert data, update data but no delete records. Here is my code. SQLBindParameter error is displayed when I try to delete a record. Can anyone help me? What could be wrong?

<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">;

<script runat="server">
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
SqlDataSource1.Insert()
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml"; >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>

</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:MySqlConnection %>"
ProviderName="<%$ ConnectionStrings:MySqlConnection.ProviderName %>"
SelectCommand="SELECT mytable.* FROM mytable"
DeleteCommand="DELETE FROM mytable WHERE id = ?"
UpdateCommand="UPDATE mytable SET name = ?, age = ? WHERE id = ?"
InsertCommand="INSERT INTO mytable(name, age) VALUES (?, ?)"
OldValuesParameterFormatString="{0}"
>
<UpdateParameters>
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="age" Type="Int32" />
</UpdateParameters>

<InsertParameters>
<asp:FormParameter Name="name" Type="String" FormField="TBname" />
<asp:FormParameter Name="age" Type="String" FormField="TBage" />
</InsertParameters>

<DeleteParameters>
<asp:Parameter Name="id" Type="Int32" />
</DeleteParameters>
</asp:SqlDataSource>

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1">
<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>
<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"
OnClientClick= "return confirm('r u sure?');">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="id" HeaderText="id" InsertVisible="False"
SortExpression="id" />
<asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
<asp:BoundField DataField="age" HeaderText="age" SortExpression="age" />
</Columns>
</asp:GridView>
<p>
<asp:TextBox ID="TBname" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</p>
<p>
<asp:TextBox ID="TBage" runat="server"></asp:TextBox>
</p>
</form>
</body>
</html>

Options: ReplyQuote


Subject
Written By
Posted
DELETE problem MySQL
January 22, 2008 01:16PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.