Проблема обновление methode в представлении сетки ASP net
Доброе утро, у меня есть проблема с asp net Grid View control на моей веб-странице. Я могу правильно получать записи по выбранному методу и заполнять вид сетки. Но я могу правильно настроить метод обновления. Кажется, ничего не происходит, когда я нажимаю кнопку обновления.
Я использую представление сетки и источник данных объекта. Я могу правильно подключиться к серверу базы данных, который является базой данных MySql server db.
Метод обновления запускается, но все его параметры, похоже, не обновляются. Только если я заставлю их читать, только метод может получить обновленное значение.
Что я уже пробовал:
Веб-страница Asp net
<%@ Page Title="" Language="C#" AutoEventWireup="true" MasterPageFile="~/Site.Master" CodeBehind="gestioneLetture_G.aspx.cs" Inherits="clearbill.portale.gestioneLetture_G" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" runat="server"> </asp:Content> <asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server"> <div> <div> POD: <div> <input type="text" id="Button1" value="..." style="float: left;" /> </div> </div> <div> <input type="button" id="btnRefresh" value="Search" style="float: left;" /> </div> </div> <asp:objectdatasource id="ObjectDataSource1" runat="server" selectmethod="GetAllLetture99" UpdateMethod="UpdateLetture99" DeleteMethod="DeleteLetture99" DataObjectTypeName = "clearbill.portale.Lettura99" typename="clearbill.portale.Tabella99Leture" ConvertNullToDBNull="True" > <UpdateParameters> <asp:formparameter name="tb099_id" formfield="tb099_id" /> <asp:formparameter name="tb099_pod_id_tb001" formfield="tb099_pod_id_tb001" /> </UpdateParameters> </asp:ObjectDataSource> <asp:gridview id="GridView1" runat="server" DataKeyNames ="tb099_id" OnRowUpdating="TaskGridView_RowUpdating" AutoGenerateColumns ="true" AllowPaging ="true" datasourceid="ObjectDataSource1" AllowSorting="True" AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" AutoGenerateSelectButton="True" OnRowUpdated="GridView1_RowUpdated" ValidateRequestMode="Enabled" ViewStateMode="Enabled"> <Columns> <asp:BoundField DataField="tb099_id" HeaderText="tb099_id" ReadOnly="true" SortExpression="tb099_id" /> <asp:BoundField DataField="tb099_pod_id_tb001" HeaderText="tb099_pod_id_tb001" ReadOnly="false" SortExpression="tb099_pod_id_tb001" /> <asp:BoundField DataField="tb099_fattura_id_tb027" HeaderText="tb099_fattura_id_tb027" ReadOnly="false" SortExpression="tb099_fattura_id_tb027" /> <asp:BoundField DataField="tb099_potcontrimp" HeaderText="tb099_potcontrimp" ReadOnly="false" SortExpression="tb099_potcontrimp" /> <asp:BoundField DataField="tb099_lettura_eaf1" HeaderText="tb099_lettura_eaf1" ReadOnly="false" SortExpression="tb099_lettura_eaf1" /> <asp:BoundField DataField="tb099_lettura_eaf2" HeaderText="tb099_lettura_eaf2" ReadOnly="false" SortExpression="tb099_lettura_eaf2" /> <asp:BoundField DataField="tb099_lettura_eaf3" HeaderText="tb099_lettura_eaf3" ReadOnly="false" SortExpression="tb099_lettura_eaf3" /> <asp:BoundField DataField="tb099_lettura_erf1" HeaderText="tb099_lettura_erf1" ReadOnly="false" SortExpression="tb099_lettura_erf1" /> <asp:BoundField DataField="tb099_lettura_erf2" HeaderText="tb099_lettura_erf2" ReadOnly="false" SortExpression="tb099_lettura_erf2" /> <asp:BoundField DataField="tb099_lettura_erf3" HeaderText="tb099_lettura_erf3" ReadOnly="false" SortExpression="tb099_lettura_erf3" /> <asp:BoundField DataField="tb099_lettura_potf1" HeaderText="tb099_lettura_potf1" ReadOnly="false" SortExpression="tb099_lettura_potf1" /> <asp:BoundField DataField="tb099_lettura_potf2" HeaderText="tb099_lettura_potf2" ReadOnly="false" SortExpression="tb099_lettura_potf2" /> <asp:BoundField DataField="tb099_lettura_potf3" HeaderText="tb099_lettura_potf3" ReadOnly="false" SortExpression="tb099_lettura_potf3" /> <asp:BoundField DataField="tb099_tipo_misura" HeaderText="tb099_tipo_misura" ReadOnly="false" SortExpression="tb099_tipo_misura" /> <asp:BoundField DataField="tb099_consumo_eaf1" HeaderText="tb099_consumo_eaf1" ReadOnly="false" SortExpression="tb099_consumo_eaf1" /> <asp:BoundField DataField="tb099_consumo_eaf2" HeaderText="tb099_consumo_eaf2" ReadOnly="false" SortExpression="tb099_consumo_eaf2" /> <asp:BoundField DataField="tb099_consumo_eaf3" HeaderText="tb099_consumo_eaf3" ReadOnly="false" SortExpression="tb099_consumo_eaf3" /> <asp:BoundField DataField="tb099_consumo_erf1" HeaderText="tb099_consumo_erf1" ReadOnly="false" SortExpression="tb099_consumo_erf1" /> <asp:BoundField DataField="tb099_consumo_erf2" HeaderText="tb099_consumo_erf2" ReadOnly="false" SortExpression="tb099_consumo_erf2" /> <asp:BoundField DataField="tb099_consumo_erf3" HeaderText="tb099_consumo_erf3" ReadOnly="false" SortExpression="tb099_consumo_erf3" /> <asp:BoundField DataField="tb099_consumo_progressivo_eaf1" HeaderText="tb099_consumo_progressivo_eaf1" ReadOnly="false" SortExpression="tb099_consumo_progressivo_eaf1" /> <asp:BoundField DataField="tb099_consumo_progressivo_eaf2" HeaderText="tb099_consumo_progressivo_eaf2" ReadOnly="false" SortExpression="tb099_consumo_progressivo_eaf2" /> <asp:BoundField DataField="tb099_consumo_progressivo_eaf3" HeaderText="tb099_consumo_progressivo_eaf3" ReadOnly="false" SortExpression="tb099_consumo_progressivo_eaf3" /> <asp:BoundField DataField="tb099_codice_pod" HeaderText="tb099_codice_pod" ReadOnly="false" SortExpression="tb099_codice_pod" /> <asp:BoundField DataField="tb099_is_iniziale" HeaderText="tb099_is_iniziale" ReadOnly="false" SortExpression="tb099_is_iniziale" /> <asp:CommandField ShowEditButton="True" /> </Columns> </asp:gridview> <script> $(document).ready(function () { $("#btnRefresh").click(function click_allpod(cb) { var v = ""; }); }); </script> </asp:Content>
За классом кода в c#
using clearbill.Common; using System; using System.Collections.Generic; using System.IO; using System.IO.Compression; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.Services; using System.Collections.ObjectModel; using System.Xml; using System.Data; using clearbill.common.ModelSubsonic; using clearbill.core.bllSubsonic; using clearbill.core.portale; using clearbill.Common.DataAccess.Model; using clearbill.core.bll; using MySql.Data; using System.Collections; using MySql.Data.MySqlClient; using System.Configuration; using System.Web.Configuration; using System.Windows.Forms; using System.Threading; using clearbill.core.bll.Import; using System.Text; using System.Reflection; using System.Web.UI.HtmlControls; using System.Xml.Schema; using System.Data.SqlClient; using SubSonic.SqlGeneration.Schema; using System.ComponentModel; namespace clearbill.portale { public partial class gestioneLetture_G : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { int i = 0; } protected void TaskGridView_RowUpdating(object sender, GridViewUpdateEventArgs e) { //Retrieve the table from the session object. DataTable dt = (DataTable)Session["TaskTable"]; //GridView1.DataBind(); } protected void GridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e) { ((clearbill.portale.gestioneLetture_G)(HttpContext.Current.Handler)).GridView1.Rows[1].RowState = DataControlRowState.Normal; GridViewRow r = ((clearbill.portale.gestioneLetture_G)(HttpContext.Current.Handler)).GridView1.Rows[1]; } } //---------------------------- DAL ----------------------------------------------------------------------------- public class Tabella99Leture { public int tb099_id; public int tb099_pod_id_tb001; public int tb099_fattura_id_tb027; public DateTime tb099_data_lettura; public decimal tb099_potcontrimp; public decimal tb099_lettura_eaf1; public decimal tb099_lettura_eaf2; public decimal tb099_lettura_eaf3; public decimal tb099_lettura_erf1; public decimal tb099_lettura_erf2; public decimal tb099_lettura_erf3; public decimal tb099_lettura_potf1; public decimal tb099_lettura_potf2; public decimal tb099_lettura_potf3; public string tb099_tipo_misura; public decimal tb099_consumo_eaf1; public decimal tb099_consumo_eaf2; public decimal tb099_consumo_eaf3; public decimal tb099_consumo_erf1; public decimal tb099_consumo_erf2; public decimal tb099_consumo_erf3; public decimal tb099_consumo_progressivo_eaf1; public decimal tb099_consumo_progressivo_eaf2; public decimal tb099_consumo_progressivo_eaf3; public string tb099_codice_pod; public bool tb099_is_iniziale; //DAL query Sql public static DataTable ExecuteDataTable(string SQL) { ConnectionStringSettings settings = WebConfigurationManager.ConnectionStrings["ClearBillMySqlConnection"]; MySqlConnection con = new MySqlConnection(settings.ConnectionString); MySqlCommand cmd = new MySqlCommand(); con.Open(); try { DataTable dt = new DataTable(); cmd = new MySqlCommand(SQL, con); MySqlDataAdapter DA = new MySqlDataAdapter(cmd); DA.Fill(dt); return dt; } catch (Exception ex) { throw ex; } finally { if (con.State == ConnectionState.Open) con.Close(); con.Dispose(); cmd.Dispose(); } } // Returns a collection of NorthwindEmployee objects. public static ICollection GetAllLetture99() { ArrayList al = new ArrayList(); string selectCommand = "SELECT * FROM tb099_riepilogo_letture_elettrico limit 100"; DataTable resSelect = ExecuteDataTable(selectCommand); IEnumerable IDs = resSelect.DefaultView; // Iterate through the Enumeration and create a // NorthwindEmployee object for each ID. foreach (DataRowView row in IDs) { string id = row["tb099_id"].ToString(); Lettura99 nwe = new Lettura99(); nwe.tb099_id = (int)row["tb099_id"]; nwe.tb099_pod_id_tb001 = (int)row["tb099_pod_id_tb001"]; nwe.tb099_fattura_id_tb027 = !DBNull.Value.Equals(row["tb099_fattura_id_tb027"]) ? (int)row["tb099_fattura_id_tb027"] : 0; nwe.tb099_data_lettura = !DBNull.Value.Equals(row["tb099_data_lettura"]) ? (DateTime)row["tb099_data_lettura"] : new DateTime(); nwe.tb099_potcontrimp = !DBNull.Value.Equals(row["tb099_potcontrimp"]) ? (decimal?)row["tb099_potcontrimp"] : 0; nwe.tb099_lettura_eaf1 = !DBNull.Value.Equals(row["tb099_lettura_eaf1"]) ? (decimal?)row["tb099_lettura_eaf1"] :0; nwe.tb099_lettura_eaf2 = !DBNull.Value.Equals(row["tb099_lettura_eaf2"]) ? (decimal?)row["tb099_lettura_eaf2"] : 0; nwe.tb099_lettura_eaf3 = !DBNull.Value.Equals(row["tb099_lettura_eaf3"]) ? (decimal?)row["tb099_lettura_eaf3"] : 0; nwe.tb099_lettura_erf1 = !DBNull.Value.Equals(row["tb099_lettura_erf1"]) ? (decimal?)row["tb099_lettura_erf1"] : 0; nwe.tb099_lettura_erf2 = !DBNull.Value.Equals(row["tb099_lettura_erf2"]) ? (decimal?)row["tb099_lettura_erf2"] : 0; nwe.tb099_lettura_erf3 = !DBNull.Value.Equals(row["tb099_lettura_erf3"]) ? (decimal?)row["tb099_lettura_erf3"] : 0; nwe.tb099_lettura_potf1 = !DBNull.Value.Equals(row["tb099_lettura_potf1"]) ? (decimal?)row["tb099_lettura_potf1"] : 0; nwe.tb099_lettura_potf2 = !DBNull.Value.Equals(row["tb099_lettura_potf2"]) ? (decimal?)row["tb099_lettura_potf2"] : 0; nwe.tb099_lettura_potf3 = !DBNull.Value.Equals(row["tb099_lettura_potf3"]) ? (decimal?)row["tb099_lettura_potf3"] :0; nwe.tb099_tipo_misura = !DBNull.Value.Equals(row["tb099_tipo_misura"]) ? (string)row["tb099_tipo_misura"] : ""; nwe.tb099_consumo_eaf1 = !DBNull.Value.Equals(row["tb099_consumo_eaf1"]) ? (decimal?)row["tb099_consumo_eaf1"] : 0; nwe.tb099_consumo_eaf2 = !DBNull.Value.Equals(row["tb099_consumo_eaf2"]) ? (decimal?)row["tb099_consumo_eaf2"] : 0; nwe.tb099_consumo_eaf3 = !DBNull.Value.Equals(row["tb099_consumo_eaf3"]) ? (decimal?)row["tb099_consumo_eaf3"] : 0; nwe.tb099_consumo_erf1 = !DBNull.Value.Equals(row["tb099_consumo_erf1"]) ? (decimal?)row["tb099_consumo_erf1"] : 0; nwe.tb099_consumo_erf2 = !DBNull.Value.Equals(row["tb099_consumo_erf2"]) ? (decimal?)row["tb099_consumo_erf2"] : 0; nwe.tb099_consumo_erf3 = !DBNull.Value.Equals(row["tb099_consumo_erf3"]) ? (decimal?)row["tb099_consumo_erf3"] : 0; nwe.tb099_consumo_progressivo_eaf1 = !DBNull.Value.Equals(row["tb099_consumo_progressivo_eaf1"]) ? (decimal?)row["tb099_consumo_progressivo_eaf1"] : 0; nwe.tb099_consumo_progressivo_eaf2 = !DBNull.Value.Equals(row["tb099_consumo_progressivo_eaf2"]) ? (decimal?)row["tb099_consumo_progressivo_eaf2"] : 0; nwe.tb099_consumo_progressivo_eaf3 = !DBNull.Value.Equals(row["tb099_consumo_progressivo_eaf3"]) ? (decimal?)row["tb099_consumo_progressivo_eaf3"] : 0; nwe.tb099_codice_pod = !DBNull.Value.Equals(row["tb099_codice_pod"]) ? (string)row["tb099_codice_pod"] : ""; if(!DBNull.Value.Equals(row["tb099_is_iniziale"]) ){ if (DBNull.Value.Equals(row["tb099_is_iniziale"]) == true) { nwe.tb099_is_iniziale = true; }else{ nwe.tb099_is_iniziale = false; } } // Add the NorthwindEmployee object to the collection. al.Add(nwe); } return al; } public static Lettura99 GetLetture99(object anID) { return new Lettura99(anID); } public static void UpdateLetture99( int tb099_id, int tb099_pod_id_tb001, int tb099_fattura_id_tb027, DateTime tb099_data_lettura, decimal tb099_potcontrimp, decimal tb099_lettura_eaf1, decimal tb099_lettura_eaf2, decimal tb099_lettura_eaf3, decimal tb099_lettura_erf1, decimal tb099_lettura_erf2, decimal tb099_lettura_erf3, decimal tb099_lettura_potf1, decimal tb099_lettura_potf2, decimal tb099_lettura_potf3, string tb099_tipo_misura, decimal tb099_consumo_eaf1, decimal tb099_consumo_eaf2, decimal tb099_consumo_eaf3, decimal tb099_consumo_erf1, decimal tb099_consumo_erf2, decimal tb099_consumo_erf3, decimal tb099_consumo_progressivo_eaf1, decimal tb099_consumo_progressivo_eaf2, decimal tb099_consumo_progressivo_eaf3, string tb099_codice_pod, bool tb099_is_iniziale ) { bool retval = true; int i = 0; string cmdSQL = "UPDATE tb099_riepilogo_letture_elettrico SET " + "tb099_pod_id_tb001 =" + tb099_pod_id_tb001 + ", " + "tb099_fattura_id_tb027 =" + tb099_fattura_id_tb027 + "," + "tb099_data_lettura ='" + tb099_data_lettura + "', " + "tb099_potcontrimp =" + tb099_potcontrimp + ", " + "tb099_lettura_eaf1 =" + tb099_lettura_eaf1 + ", " + "tb099_lettura_eaf2 =" + tb099_lettura_eaf2 + ", " + "tb099_lettura_eaf3 =" + tb099_lettura_eaf3 + ", " + "tb099_lettura_erf1 =" + tb099_lettura_erf1 + ", " + "tb099_lettura_erf2 =" + tb099_lettura_erf2 + ", " + "tb099_lettura_erf3 =" + tb099_lettura_erf3 + ", " + "tb099_lettura_potf1 =" + tb099_lettura_potf1 + ", " + "tb099_lettura_potf2 =" + tb099_lettura_potf2 + ", " + "tb099_lettura_potf3 =" + tb099_lettura_potf3 + ", " + "tb099_tipo_misura ='" + tb099_tipo_misura + "', " + "tb099_consumo_eaf1 =" + tb099_consumo_eaf1 + ", " + "tb099_consumo_eaf2 =" + tb099_consumo_eaf2 + ", " + "tb099_consumo_eaf3 =" + tb099_consumo_eaf3 + ", " + "tb099_consumo_erf1 =" + tb099_consumo_erf1 + ", " + "tb099_consumo_erf2 =" + tb099_consumo_erf2 + ", " + "tb099_consumo_erf3 =" + tb099_consumo_erf3 + ", " + "tb099_consumo_progressivo_eaf1 =" + tb099_consumo_progressivo_eaf1 + ", " + "tb099_consumo_progressivo_eaf2 =" + tb099_consumo_progressivo_eaf2 + ", " + "tb099_consumo_progressivo_eaf3 =" + tb099_consumo_progressivo_eaf3 + ", " + "tb099_codice_pod ='" + tb099_codice_pod + "', " + "tb099_is_iniziale =" + tb099_is_iniziale + " " + "WHERE tb099_id =" + tb099_id + ";"; //ExecuteDataTable(cmdSQL); //bool retval = ne.Save(); if (!retval) { throw new NorthwindDataException("UpdateEmployee failed."); } } public static void UpdateLetture99(Lettura99 entry) { int idSel = entry.tb099_id; //Riga selezionata GridViewRow r = ((clearbill.portale.gestioneLetture_G)(HttpContext.Current.Handler)).GridView1.Rows[idSel]; //var v1 = ((clearbill.portale.gestioneLetture_G)(HttpContext.Current.Handler)).ObjectDataSource1.; var v = r.Cells[1].Text; bool retval = true; int i = 0; string cmdSQL = "UPDATE tb099_riepilogo_letture_elettrico SET " + "tb099_pod_id_tb001 =" + r.Cells[1].Text +", " + "tb099_fattura_id_tb027 =" + r.Cells[2].Text + "," + "tb099_data_lettura ='" + r.Cells[3].Text + "', " + "tb099_potcontrimp =" + r.Cells[4].Text + ", " + "tb099_lettura_eaf1 =" + r.Cells[5].Text + ", " + "tb099_lettura_eaf2 =" + r.Cells[6].Text + ", " + "tb099_lettura_eaf3 =" + r.Cells[7].Text + ", " + "tb099_lettura_erf1 =" + r.Cells[8].Text + ", " + "tb099_lettura_erf2 =" + r.Cells[9].Text + ", " + "tb099_lettura_erf3 =" + r.Cells[10].Text + ", " + "tb099_lettura_potf1 =" + r.Cells[11].Text + ", " + "tb099_lettura_potf2 =" + r.Cells[12].Text + ", " + "tb099_lettura_potf3 =" + r.Cells[13].Text + ", " + "tb099_tipo_misura ='" + r.Cells[14].Text + "', " + "tb099_consumo_eaf1 =" + r.Cells[15].Text + ", " + "tb099_consumo_eaf2 =" + r.Cells[16].Text + ", " + "tb099_consumo_eaf3 =" + r.Cells[17].Text + ", " + "tb099_consumo_erf1 =" + r.Cells[18].Text + ", " + "tb099_consumo_erf2 =" + r.Cells[19].Text + ", " + "tb099_consumo_erf3 =" + r.Cells[20].Text + ", " + "tb099_consumo_progressivo_eaf1 =" + r.Cells[21].Text + ", " + "tb099_consumo_progressivo_eaf2 =" + r.Cells[22].Text + ", " + "tb099_consumo_progressivo_eaf3 =" + r.Cells[23].Text + ", " + "tb099_codice_pod ='" + r.Cells[24].Text + "', " + "tb099_is_iniziale =" + r.Cells[25].Text + " " + "WHERE tb099_id =" + idSel + ";"; //ExecuteDataTable(cmdSQL); //bool retval = ne.Save(); if (!retval) { throw new NorthwindDataException("UpdateEmployee failed."); } } public static void DeleteLetture99(Lettura99 ne) { string cmdSQL =" DELETE FROM tb099_riepilogo_letture_elettrico SET " + ""; } } public class Lettura99 : INotifyPropertyChanged { [SubSonicPrimaryKey] public int tb099_id { get; set; } public int tb099_pod_id_tb001 { get; set; } public int? tb099_fattura_id_tb027 { get; set; } public DateTime? tb099_data_lettura { get; set; } [SubSonicNumericPrecision(20, 6)] public decimal? tb099_potcontrimp { get; set; } [SubSonicNumericPrecision(20, 6)] public decimal? tb099_lettura_eaf1 { get; set; } [SubSonicNumericPrecision(20, 6)] public decimal? tb099_lettura_eaf2 { get; set; } [SubSonicNumericPrecision(20, 6)] public decimal? tb099_lettura_eaf3 { get; set; } [SubSonicNumericPrecision(20, 6)] public decimal? tb099_lettura_erf1 { get; set; } [SubSonicNumericPrecision(20, 6)] public decimal? tb099_lettura_erf2 { get; set; } [SubSonicNumericPrecision(20, 6)] public decimal? tb099_lettura_erf3 { get; set; } [SubSonicNumericPrecision(20, 6)] public decimal? tb099_lettura_potf1 { get; set; } [SubSonicNumericPrecision(20, 6)] public decimal? tb099_lettura_potf2 { get; set; } [SubSonicNumericPrecision(20, 6)] public decimal? tb099_lettura_potf3 { get; set; } [SubSonicNullString] public string tb099_tipo_misura { get; set; } [SubSonicNumericPrecision(20, 6)] public decimal? tb099_consumo_eaf1 { get; set; } [SubSonicNumericPrecision(20, 6)] public decimal? tb099_consumo_eaf2 { get; set; } [SubSonicNumericPrecision(20, 6)] public decimal? tb099_consumo_eaf3 { get; set; } [SubSonicNumericPrecision(20, 6)] public decimal? tb099_consumo_erf1 { get; set; } [SubSonicNumericPrecision(20, 6)] public decimal? tb099_consumo_erf2 { get; set; } [SubSonicNumericPrecision(20, 6)] public decimal? tb099_consumo_erf3 { get; set; } [SubSonicNumericPrecision(20, 6)] public decimal? tb099_consumo_progressivo_eaf1 { get; set; } [SubSonicNumericPrecision(20, 6)] public decimal? tb099_consumo_progressivo_eaf2 { get; set; } [SubSonicNumericPrecision(20, 6)] public decimal? tb099_consumo_progressivo_eaf3 { get; set; } [SubSonicNullString] public string tb099_codice_pod { get; set; } [SubSonicDefaultSetting(0)] public bool? tb099_is_iniziale { get; set; } public Lettura99(object anID) { } public Lettura99() { int i = 0; /* this.ID = anID; ConnectionStringSettings cts = ConfigurationManager.ConnectionStrings["NorthwindConnection"]; SqlConnection conn = new SqlConnection(cts.ConnectionString); SqlCommand sc = new SqlCommand(" SELECT FirstName,LastName,Title,TitleOfCourtesy,ReportsTo " + " FROM Employees " + " WHERE EmployeeID = @empId", conn); // Add the employee ID parameter and set its value. sc.Parameters.Add(new SqlParameter("@empId", SqlDbType.Int)).Value = Int32.Parse(anID.ToString()); SqlDataReader sdr = null; try { conn.Open(); sdr = sc.ExecuteReader(); // This is not a while loop. It only loops once. if (sdr != null && sdr.Read()) { // The IEnumerable contains DataRowView objects. this.firstName = sdr["FirstName"].ToString(); this.lastName = sdr["LastName"].ToString(); this.title = sdr["Title"].ToString(); this.titleOfCourtesy = sdr["TitleOfCourtesy"].ToString(); if (!sdr.IsDBNull(4)) { this.reportsTo = sdr.GetInt32(4); } } else { throw new NorthwindDataException("Data not loaded for employee id."); } } finally { try { if (sdr != null) sdr.Close(); conn.Close(); } catch (SqlException) { // Log an event in the Application Event Log. throw; } }*/ } // This method is called by the Set accessor of each property. // The CallerMemberName attribute that is applied to the optional propertyName // parameter causes the property name of the caller to be substituted as an argument. private void NotifyPropertyChanged([System.Runtime.CompilerServices.CallerMemberName] String propertyName = "") { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } public bool Save() { return true; } public event PropertyChangedEventHandler PropertyChanged; } internal class NorthwindDataException : Exception { public NorthwindDataException(string msg) : base(msg) { } } //http://www.aspsnippets.com/Articles/Display-data-from-database-in-HTML-table-in-ASPNet.aspx //https://msdn.microsoft.com/en-us/library/ms972948.aspx }
Karthik_Mahalingam
публикуйте только соответствующий код, не вставляйте весь код целиком.
Andy_Bell
Извините, но я подумал, что было бы полезно найти проблему. Я думал, что это зависит от какого-то компонента Asp или определения methode, поэтому я не смог выбрать конкретные части кода. В дальнейшем я стараюсь быть более строгим.
Karthik_Mahalingam
Хм, но трудно отследить весь код..
Andy_Bell
Я в твоих руках. Любые сладости будут оценены по достоинству
Karthik_Mahalingam
в какой части вы застряли? упростите проблему.
Andy_Bell
Проблема заключается в классе Tabella99Leture, функции UpdateLetture99. Он связан с ObjectDataSource1. Когда он триггируется, все его параметры устанавливаются в нуль (или 0 в виде числовых полей).
Karthik_Mahalingam
убедитесь, что все поля сопоставлены в разделе "UpdateParameters" в соответствии с
https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.objectdatasource.update(v=vs. 110).aspx
попробуйте создать простой poc и проверьте
Andy_Bell
Я сделал так, как вы предлагаете. Я удаляю все параметры и свойства в классе, оставляя только первые два. Я изменил методы Select и Update с помощью 2-х файлов параметров, но у меня тот же результат.
Karthik_Mahalingam
создайте простой poc и поделитесь кодом, я проверю и дам вам знать.
Andy_Bell
Большое спасибо, но что я могу сделать? Как я могу реализовать этот poc и где я могу им поделиться?
Karthik_Mahalingam
https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.objectdatasource.update(v=vs. 110).aspx
это само по себе poc, попробуйте преуспеть в этом.