Ciao a tutti.
Devo dire che sono piacevolmente sorpreso dalla potenza di ASP.Net 4, ho fatto diversi passi avanti, ma sono bloccato sulla modalità di update dei dati della tabella.
Il mio testo di riferimento è «ASP.NET 4 in C# e VB», autori Bill Evjen, Scott Hanselman, Devin Rader.
Ricevo il seguente errore ed i records nella tabella non si modificano:
An error occurred while attempting to update the row.
Perchè?
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Odbc" %>
<%@ Import Namespace="System.Configuration" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
public void Page_Load (Object sender, EventArgs e)
{
OdbcConnection myConnectionString = new OdbcConnection(ConfigurationManager.ConnectionStrings["ConnMySQL"].ConnectionString);
myConnectionString.Open();
myConnectionString.Close();
}
protected void GridView1_RowUpdated(Object sender, GridViewUpdatedEventArgs e)
{
if (e.Exception == null)
{
Message.Text = "Row updated successfully.";
}
else
{
e.ExceptionHandled = true;
Message.Text = "An error occurred while attempting to update the row.";
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:label id="Message" forecolor="Red" runat="server"/>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnMySQL %>"
ProviderName="<%$ ConnectionStrings:ConnMySQL.ProviderName %>"
DataSourceMode="DataSet"
SelectCommand="SELECT * FROM tbl_login"
UpdateCommand="UPDATE tbl_login SET nome=@nome, cognome=@cognome WHERE ID=@original_ID">
<UpdateParameters>
<asp:Parameter Type="String" Name="nome" />
<asp:Parameter Type="String" Name="cognome" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" PageSize="20" DataSourceID="SqlDataSource1"
DataKeyNames="ID" AutoGenerateColumns="False" AutoGenerateEditButton="False"
onrowupdated="GridView1_RowUpdated">
<PagerStyle HorizontalAlign="Left" />
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="true" />
<asp:BoundField DataField="Email" HeaderText="Email" HtmlEncode="False" DataFormatString="<a href='mailto:{0}'>{0}</a>" />
<asp:BoundField DataField="nome" HeaderText="nome" />
<asp:BoundField DataField="cognome" HeaderText="cognome" />
<asp:CommandField ShowHeader="true" HeaderText="Modifica" ShowEditButton="true" />
<asp:TemplateField>
<ItemTemplate>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerSettings Position="TopAndBottom"
FirstPageText="Prima pagina"
LastPageText="Ultima pagina"
Mode="NextPreviousFirstLast" />
<PagerSettings />
</asp:GridView>
</div>
</form>
</body>
</html>
Modificato da orcim il 18 marzo 2011 15.45 -
Modificato da orcim il 18 marzo 2011 16.20 -