日期:2014-05-17  浏览次数:20390 次

asp.net无法更新数据库!
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Business;
using Entity;

public partial class EgNewsEdit : System.Web.UI.Page
{
  NewsBusiness nb = new NewsBusiness();
  NewsEntity ne = new NewsEntity();
  protected void Page_Load(object sender, EventArgs e)
  {
  Label2.Text = Convert.ToString(Session["newsid"]);
  DataSet ds = nb.GetNewsInfoByID(Label2.Text);
  TextBox1.Text = ds.Tables[0].Rows[0][1].ToString();
  TextBox2.Text = ds.Tables[0].Rows[0][2].ToString();
  TextBox3.Text = ds.Tables[0].Rows[0][3].ToString();
  TextBox4.Text = ds.Tables[0].Rows[0][4].ToString();
  FreeTextBox1.Text = ds.Tables[0].Rows[0][5].ToString();
  Label1.Text = ds.Tables[0].Rows[0][6].ToString();
  DropDownList1.Text = ds.Tables[0].Rows[0][7].ToString();
  DropDownList2.Text = ds.Tables[0].Rows[0][8].ToString();
  ImageButton1.ImageUrl = ds.Tables[0].Rows[0][9].ToString();
  DropDownList3.Text = ds.Tables[0].Rows[0][10].ToString();
  }
  protected void Button1_Click(object sender, EventArgs e)
  {
  ne.ID = Convert.ToInt32(Label2.Text);
  ne.Name = TextBox1.Text;
  ne.Writer = TextBox2.Text;
  ne.Source = TextBox3.Text;
  ne.Editor = TextBox4.Text;
  ne.Content = FreeTextBox1.Text;
  ne.Time = Label1.Text;
  ne.Range = DropDownList1.Text;
  ne.Classify = DropDownList2.Text;
  ne.Image = ImageButton1.ImageUrl;
  ne.Hot = DropDownList3.Text;
  int count = nb.UpdateNews(ne);
  if (count >= 0)
  {
  Response.Redirect("EgNewsList.aspx");
  }
  }
}
就是先从其他网页获取数据,点击Button1再更新到数据库,但Button1_Click无法将数据更新到数据库,求高手指点啊!谢谢了~

------解决方案--------------------
检查int count = nb.UpdateNews(ne);中UpdateNews方法的实现。
------解决方案--------------------
少打了一句 在 UpdateNews里 看看有木有异常